/* registry.c generated by valac 0.56.1, the Vala compiler
 * generated from registry.vala, do not modify */

/*
 * Seahorse
 *
 * Copyright (C) 2008 Stefan Walter
 * Copyright (C) 2013 Stefan Walter
 *
 * This program 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.
 *
 * This program 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 program; if not, see <http://www.gnu.org/licenses/>.
 */

#include "seahorse-common.h"
#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include <glib-object.h>

enum  {
	SEAHORSE_REGISTRY_0_PROPERTY,
	SEAHORSE_REGISTRY_NUM_PROPERTIES
};
static GParamSpec* seahorse_registry_properties[SEAHORSE_REGISTRY_NUM_PROPERTIES];
#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)))

struct _SeahorseRegistryPrivate {
	GHashTable* _objects;
};

static gint SeahorseRegistry_private_offset;
static gpointer seahorse_registry_parent_class = NULL;
static SeahorseRegistry* seahorse_registry__singleton;
static SeahorseRegistry* seahorse_registry__singleton = NULL;

static SeahorseRegistry* seahorse_registry_instance (void);
static void _g_object_unref0_ (gpointer var);
static GObject * seahorse_registry_constructor (GType type,
                                         guint n_construct_properties,
                                         GObjectConstructParam * construct_properties);
static void _g_free0_ (gpointer var);
static void _g_hash_table_unref0_ (gpointer var);
static void seahorse_registry_finalize (GObject * obj);
static GType seahorse_registry_get_type_once (void);

static inline gpointer
seahorse_registry_get_instance_private (SeahorseRegistry* self)
{
	return G_STRUCT_MEMBER_P (self, SeahorseRegistry_private_offset);
}

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

static SeahorseRegistry*
seahorse_registry_instance (void)
{
	SeahorseRegistry* _tmp0_;
	SeahorseRegistry* _tmp2_;
	SeahorseRegistry* _tmp3_;
	SeahorseRegistry* result;
	_tmp0_ = seahorse_registry__singleton;
	if (_tmp0_ == NULL) {
		SeahorseRegistry* _tmp1_;
		_tmp1_ = seahorse_registry_new ();
		_g_object_unref0 (seahorse_registry__singleton);
		seahorse_registry__singleton = _tmp1_;
	}
	_tmp2_ = seahorse_registry__singleton;
	_tmp3_ = _g_object_ref0 (_tmp2_);
	result = _tmp3_;
	return result;
}

void
seahorse_registry_cleanup (void)
{
	_g_object_unref0 (seahorse_registry__singleton);
	seahorse_registry__singleton = NULL;
}

static gpointer
_g_hash_table_ref0 (gpointer self)
{
	return self ? g_hash_table_ref (self) : NULL;
}

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

void
seahorse_registry_register_object (GObject* object,
                                   const gchar* category)
{
	SeahorseRegistry* registry = NULL;
	SeahorseRegistry* _tmp0_;
	GHashTable* oset = NULL;
	SeahorseRegistry* _tmp1_;
	GHashTable* _tmp2_;
	gconstpointer _tmp3_;
	GHashTable* _tmp4_;
	GHashTable* _tmp5_;
	GHashTable* _tmp14_;
	GObject* _tmp15_;
	GObject* _tmp16_;
	g_return_if_fail (object != NULL);
	g_return_if_fail (category != NULL);
	_tmp0_ = seahorse_registry_instance ();
	registry = _tmp0_;
	_tmp1_ = registry;
	_tmp2_ = _tmp1_->priv->_objects;
	_tmp3_ = g_hash_table_lookup (_tmp2_, category);
	_tmp4_ = _g_hash_table_ref0 ((GHashTable*) _tmp3_);
	_g_hash_table_unref0 (oset);
	oset = _tmp4_;
	_tmp5_ = oset;
	if (_tmp5_ == NULL) {
		GHashFunc _tmp6_;
		GEqualFunc _tmp7_;
		GHashTable* _tmp8_;
		SeahorseRegistry* _tmp9_;
		GHashTable* _tmp10_;
		gchar* _tmp11_;
		GHashTable* _tmp12_;
		GHashTable* _tmp13_;
		_tmp6_ = g_direct_hash;
		_tmp7_ = g_direct_equal;
		_tmp8_ = g_hash_table_new_full (_tmp6_, _tmp7_, _g_object_unref0_, _g_object_unref0_);
		_g_hash_table_unref0 (oset);
		oset = _tmp8_;
		_tmp9_ = registry;
		_tmp10_ = _tmp9_->priv->_objects;
		_tmp11_ = g_strdup (category);
		_tmp12_ = oset;
		_tmp13_ = _g_hash_table_ref0 (_tmp12_);
		g_hash_table_replace (_tmp10_, _tmp11_, _tmp13_);
	}
	_tmp14_ = oset;
	_tmp15_ = _g_object_ref0 (object);
	_tmp16_ = _g_object_ref0 (object);
	g_hash_table_replace (_tmp14_, _tmp15_, _tmp16_);
	_g_hash_table_unref0 (oset);
	_g_object_unref0 (registry);
}

GObject*
seahorse_registry_object_instance (const gchar* category)
{
	SeahorseRegistry* registry = NULL;
	SeahorseRegistry* _tmp0_;
	GHashTable* oset = NULL;
	SeahorseRegistry* _tmp1_;
	GHashTable* _tmp2_;
	gconstpointer _tmp3_;
	GHashTable* _tmp4_;
	GHashTable* _tmp5_;
	GHashTableIter iter = {0};
	GHashTable* _tmp6_;
	GObject* key = NULL;
	GObject* value = NULL;
	GObject* result;
	g_return_val_if_fail (category != NULL, NULL);
	_tmp0_ = seahorse_registry_instance ();
	registry = _tmp0_;
	_tmp1_ = registry;
	_tmp2_ = _tmp1_->priv->_objects;
	_tmp3_ = g_hash_table_lookup (_tmp2_, category);
	_tmp4_ = _g_hash_table_ref0 ((GHashTable*) _tmp3_);
	_g_hash_table_unref0 (oset);
	oset = _tmp4_;
	_tmp5_ = oset;
	if (_tmp5_ == NULL) {
		result = NULL;
		_g_hash_table_unref0 (oset);
		_g_object_unref0 (registry);
		return result;
	}
	_tmp6_ = oset;
	g_hash_table_iter_init (&iter, _tmp6_);
	while (TRUE) {
		gconstpointer _tmp7_ = NULL;
		gconstpointer _tmp8_ = NULL;
		gboolean _tmp9_;
		GObject* _tmp10_;
		GObject* _tmp11_;
		_tmp9_ = g_hash_table_iter_next (&iter, (gpointer*) (&_tmp7_), (gpointer*) (&_tmp8_));
		key = _tmp7_;
		value = _tmp8_;
		if (!_tmp9_) {
			break;
		}
		_tmp10_ = value;
		_tmp11_ = _g_object_ref0 (_tmp10_);
		result = _tmp11_;
		_g_hash_table_unref0 (oset);
		_g_object_unref0 (registry);
		return result;
	}
	result = NULL;
	_g_hash_table_unref0 (oset);
	_g_object_unref0 (registry);
	return result;
}

GList*
seahorse_registry_object_instances (const gchar* category)
{
	SeahorseRegistry* registry = NULL;
	SeahorseRegistry* _tmp0_;
	GHashTable* oset = NULL;
	GList* insts = NULL;
	SeahorseRegistry* _tmp1_;
	GHashTable* _tmp2_;
	gconstpointer _tmp3_;
	GHashTable* _tmp4_;
	GHashTable* _tmp5_;
	GHashTableIter iter = {0};
	GHashTable* _tmp6_;
	GObject* key = NULL;
	GObject* value = NULL;
	GList* result;
	g_return_val_if_fail (category != NULL, NULL);
	_tmp0_ = seahorse_registry_instance ();
	registry = _tmp0_;
	insts = NULL;
	_tmp1_ = registry;
	_tmp2_ = _tmp1_->priv->_objects;
	_tmp3_ = g_hash_table_lookup (_tmp2_, category);
	_tmp4_ = _g_hash_table_ref0 ((GHashTable*) _tmp3_);
	_g_hash_table_unref0 (oset);
	oset = _tmp4_;
	_tmp5_ = oset;
	if (_tmp5_ == NULL) {
		result = insts;
		_g_hash_table_unref0 (oset);
		_g_object_unref0 (registry);
		return result;
	}
	_tmp6_ = oset;
	g_hash_table_iter_init (&iter, _tmp6_);
	while (TRUE) {
		gconstpointer _tmp7_ = NULL;
		gconstpointer _tmp8_ = NULL;
		gboolean _tmp9_;
		GObject* _tmp10_;
		GObject* _tmp11_;
		_tmp9_ = g_hash_table_iter_next (&iter, (gpointer*) (&_tmp7_), (gpointer*) (&_tmp8_));
		key = _tmp7_;
		value = _tmp8_;
		if (!_tmp9_) {
			break;
		}
		_tmp10_ = value;
		_tmp11_ = _g_object_ref0 (_tmp10_);
		insts = g_list_append (insts, _tmp11_);
	}
	result = insts;
	_g_hash_table_unref0 (oset);
	_g_object_unref0 (registry);
	return result;
}

SeahorseRegistry*
seahorse_registry_construct (GType object_type)
{
	SeahorseRegistry * self = NULL;
	self = (SeahorseRegistry*) g_object_new (object_type, NULL);
	return self;
}

SeahorseRegistry*
seahorse_registry_new (void)
{
	return seahorse_registry_construct (SEAHORSE_TYPE_REGISTRY);
}

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

static void
_g_hash_table_unref0_ (gpointer var)
{
	(var == NULL) ? NULL : (var = (g_hash_table_unref (var), NULL));
}

static GObject *
seahorse_registry_constructor (GType type,
                               guint n_construct_properties,
                               GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	SeahorseRegistry * self;
	GHashFunc _tmp0_;
	GEqualFunc _tmp1_;
	GHashTable* _tmp2_;
	parent_class = G_OBJECT_CLASS (seahorse_registry_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, SEAHORSE_TYPE_REGISTRY, SeahorseRegistry);
	_tmp0_ = g_str_hash;
	_tmp1_ = g_str_equal;
	_tmp2_ = g_hash_table_new_full (_tmp0_, _tmp1_, _g_free0_, _g_hash_table_unref0_);
	_g_hash_table_unref0 (self->priv->_objects);
	self->priv->_objects = _tmp2_;
	return obj;
}

static void
seahorse_registry_class_init (SeahorseRegistryClass * klass,
                              gpointer klass_data)
{
	seahorse_registry_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &SeahorseRegistry_private_offset);
	G_OBJECT_CLASS (klass)->constructor = seahorse_registry_constructor;
	G_OBJECT_CLASS (klass)->finalize = seahorse_registry_finalize;
}

static void
seahorse_registry_instance_init (SeahorseRegistry * self,
                                 gpointer klass)
{
	self->priv = seahorse_registry_get_instance_private (self);
}

static void
seahorse_registry_finalize (GObject * obj)
{
	SeahorseRegistry * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, SEAHORSE_TYPE_REGISTRY, SeahorseRegistry);
	_g_hash_table_unref0 (self->priv->_objects);
	G_OBJECT_CLASS (seahorse_registry_parent_class)->finalize (obj);
}

 G_GNUC_NO_INLINE static GType
seahorse_registry_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (SeahorseRegistryClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) seahorse_registry_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (SeahorseRegistry), 0, (GInstanceInitFunc) seahorse_registry_instance_init, NULL };
	GType seahorse_registry_type_id;
	seahorse_registry_type_id = g_type_register_static (G_TYPE_OBJECT, "SeahorseRegistry", &g_define_type_info, 0);
	SeahorseRegistry_private_offset = g_type_add_instance_private (seahorse_registry_type_id, sizeof (SeahorseRegistryPrivate));
	return seahorse_registry_type_id;
}

GType
seahorse_registry_get_type (void)
{
	static volatile gsize seahorse_registry_type_id__once = 0;
	if (g_once_init_enter (&seahorse_registry_type_id__once)) {
		GType seahorse_registry_type_id;
		seahorse_registry_type_id = seahorse_registry_get_type_once ();
		g_once_init_leave (&seahorse_registry_type_id__once, seahorse_registry_type_id);
	}
	return seahorse_registry_type_id__once;
}

