/* gca-backend-manager.c generated by valac 0.28.0.11-bbdd, the Vala compiler
 * generated from gca-backend-manager.vala, do not modify */

/*
 * This file is part of gedit-code-assistant.
 *
 * Copyright (C) 2011 - Jesse van den Kieboom
 *
 * gedit-code-assistant is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * gedit-code-assistant 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with gedit-code-assistant.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <glib.h>
#include <glib-object.h>
#include <gee.h>
#include <stdlib.h>
#include <string.h>
#include <gio/gio.h>
#include <libpeas/peas.h>
#include <config.h>
#include <gobject/gvaluecollector.h>


#define GCA_TYPE_BACKEND_MANAGER (gca_backend_manager_get_type ())
#define GCA_BACKEND_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GCA_TYPE_BACKEND_MANAGER, GcaBackendManager))
#define GCA_BACKEND_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GCA_TYPE_BACKEND_MANAGER, GcaBackendManagerClass))
#define GCA_IS_BACKEND_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GCA_TYPE_BACKEND_MANAGER))
#define GCA_IS_BACKEND_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GCA_TYPE_BACKEND_MANAGER))
#define GCA_BACKEND_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GCA_TYPE_BACKEND_MANAGER, GcaBackendManagerClass))

typedef struct _GcaBackendManager GcaBackendManager;
typedef struct _GcaBackendManagerClass GcaBackendManagerClass;
typedef struct _GcaBackendManagerPrivate GcaBackendManagerPrivate;

#define GCA_TYPE_BACKEND (gca_backend_get_type ())
#define GCA_BACKEND(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GCA_TYPE_BACKEND, GcaBackend))
#define GCA_BACKEND_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GCA_TYPE_BACKEND, GcaBackendClass))
#define GCA_IS_BACKEND(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GCA_TYPE_BACKEND))
#define GCA_IS_BACKEND_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GCA_TYPE_BACKEND))
#define GCA_BACKEND_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GCA_TYPE_BACKEND, GcaBackendClass))

typedef struct _GcaBackend GcaBackend;
typedef struct _GcaBackendClass GcaBackendClass;

#define GCA_BACKEND_MANAGER_TYPE_INDENT_BACKEND_INFO (gca_backend_manager_indent_backend_info_get_type ())
#define GCA_BACKEND_MANAGER_INDENT_BACKEND_INFO(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GCA_BACKEND_MANAGER_TYPE_INDENT_BACKEND_INFO, GcaBackendManagerIndentBackendInfo))
#define GCA_BACKEND_MANAGER_INDENT_BACKEND_INFO_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GCA_BACKEND_MANAGER_TYPE_INDENT_BACKEND_INFO, GcaBackendManagerIndentBackendInfoClass))
#define GCA_BACKEND_MANAGER_IS_INDENT_BACKEND_INFO(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GCA_BACKEND_MANAGER_TYPE_INDENT_BACKEND_INFO))
#define GCA_BACKEND_MANAGER_IS_INDENT_BACKEND_INFO_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GCA_BACKEND_MANAGER_TYPE_INDENT_BACKEND_INFO))
#define GCA_BACKEND_MANAGER_INDENT_BACKEND_INFO_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GCA_BACKEND_MANAGER_TYPE_INDENT_BACKEND_INFO, GcaBackendManagerIndentBackendInfoClass))

typedef struct _GcaBackendManagerIndentBackendInfo GcaBackendManagerIndentBackendInfo;
typedef struct _GcaBackendManagerIndentBackendInfoClass GcaBackendManagerIndentBackendInfoClass;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_settings_schema_unref0(var) ((var == NULL) ? NULL : (var = (g_settings_schema_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_settings_schema_source_unref0(var) ((var == NULL) ? NULL : (var = (g_settings_schema_source_unref (var), NULL)))
#define __vala_PeasPluginInfo_free0(var) ((var == NULL) ? NULL : (var = (_vala_PeasPluginInfo_free (var), NULL)))
#define _g_variant_unref0(var) ((var == NULL) ? NULL : (var = (g_variant_unref (var), NULL)))
#define _g_variant_iter_free0(var) ((var == NULL) ? NULL : (var = (g_variant_iter_free (var), NULL)))
#define _gca_backend_manager_unref0(var) ((var == NULL) ? NULL : (var = (gca_backend_manager_unref (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
typedef struct _GcaBackendManagerBackendData GcaBackendManagerBackendData;
typedef struct _GcaBackendManagerIndentBackendInfoPrivate GcaBackendManagerIndentBackendInfoPrivate;
typedef struct _GcaParamSpecBackendManager GcaParamSpecBackendManager;

struct _GcaBackendManager {
	GTypeInstance parent_instance;
	volatile int ref_count;
	GcaBackendManagerPrivate * priv;
};

struct _GcaBackendManagerClass {
	GTypeClass parent_class;
	void (*finalize) (GcaBackendManager *self);
};

struct _GcaBackendManagerPrivate {
	GeeHashMap* d_backends;
	GeeHashMap* d_language_mapping;
	GSettings* d_settings;
	GeeHashMap* d_indent_backends;
	PeasEngine* d_engine;
};

struct _GcaBackendManagerBackendData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GSimpleAsyncResult* _async_result;
	GcaBackendManager* self;
	gchar* language;
	GcaBackend* result;
	gchar* lang;
	const gchar* _tmp0_;
	gchar* _tmp1_;
	GeeHashMap* _tmp2_;
	const gchar* _tmp3_;
	gboolean _tmp4_;
	GeeHashMap* _tmp5_;
	const gchar* _tmp6_;
	gpointer _tmp7_;
	GeeHashMap* _tmp8_;
	const gchar* _tmp9_;
	gboolean _tmp10_;
	GeeHashMap* _tmp11_;
	const gchar* _tmp12_;
	gpointer _tmp13_;
	GcaBackend* backend;
	GcaBackend* _tmp14_;
	const gchar* _tmp15_;
	GcaBackend* _tmp16_;
	GcaBackend* _tmp17_;
	GError* e;
	GError* _tmp18_;
	const gchar* _tmp19_;
	GeeHashMap* _tmp20_;
	const gchar* _tmp21_;
	GcaBackend* _tmp22_;
	GError * _inner_error_;
};

struct _GcaBackendManagerIndentBackendInfo {
	GObject parent_instance;
	GcaBackendManagerIndentBackendInfoPrivate * priv;
};

struct _GcaBackendManagerIndentBackendInfoClass {
	GObjectClass parent_class;
};

struct _GcaBackendManagerIndentBackendInfoPrivate {
	PeasPluginInfo* _info;
};

struct _GcaParamSpecBackendManager {
	GParamSpec parent_instance;
};


static gpointer gca_backend_manager_parent_class = NULL;
static GcaBackendManager* gca_backend_manager_s_instance;
static GcaBackendManager* gca_backend_manager_s_instance = NULL;
static gpointer gca_backend_manager_indent_backend_info_parent_class = NULL;

gpointer gca_backend_manager_ref (gpointer instance);
void gca_backend_manager_unref (gpointer instance);
GParamSpec* gca_param_spec_backend_manager (const gchar* name, const gchar* nick, const gchar* blurb, GType object_type, GParamFlags flags);
void gca_value_set_backend_manager (GValue* value, gpointer v_object);
void gca_value_take_backend_manager (GValue* value, gpointer v_object);
gpointer gca_value_get_backend_manager (const GValue* value);
GType gca_backend_manager_get_type (void) G_GNUC_CONST;
GType gca_backend_get_type (void) G_GNUC_CONST;
GType gca_backend_manager_indent_backend_info_get_type (void) G_GNUC_CONST;
#define GCA_BACKEND_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GCA_TYPE_BACKEND_MANAGER, GcaBackendManagerPrivate))
enum  {
	GCA_BACKEND_MANAGER_DUMMY_PROPERTY
};
static GcaBackendManager* gca_backend_manager_new (void);
static GcaBackendManager* gca_backend_manager_construct (GType object_type);
static void gca_backend_manager_update_language_mapping (GcaBackendManager* self);
static void ___lambda9_ (GcaBackendManager* self);
static void ____lambda9__g_settings_changed (GSettings* _sender, const gchar* key, gpointer self);
static void gca_backend_manager_register_backends (GcaBackendManager* self);
static PeasPluginInfo* _vala_PeasPluginInfo_copy (PeasPluginInfo* self);
static void _vala_PeasPluginInfo_free (PeasPluginInfo* self);
GcaBackendManagerIndentBackendInfo* gca_backend_manager_indent_backend_info_new (PeasPluginInfo* info);
GcaBackendManagerIndentBackendInfo* gca_backend_manager_indent_backend_info_construct (GType object_type, PeasPluginInfo* info);
static void gca_backend_manager_backend_data_free (gpointer _data);
void gca_backend_manager_backend (GcaBackendManager* self, const gchar* language, GAsyncReadyCallback _callback_, gpointer _user_data_);
GcaBackend* gca_backend_manager_backend_finish (GcaBackendManager* self, GAsyncResult* _res_);
static gboolean gca_backend_manager_backend_co (GcaBackendManagerBackendData* _data_);
void gca_backend_create (const gchar* language, GAsyncReadyCallback _callback_, gpointer _user_data_);
GcaBackend* gca_backend_create_finish (GAsyncResult* _res_, GError** error);
static void gca_backend_manager_backend_ready (GObject* source_object, GAsyncResult* _res_, gpointer _user_data_);
void gca_log_debug (const gchar* format, ...);
GcaBackendManagerIndentBackendInfo* gca_backend_manager_indent_backend_info (GcaBackendManager* self, const gchar* language);
GcaBackendManager* gca_backend_manager_get_instance (void);
#define GCA_BACKEND_MANAGER_INDENT_BACKEND_INFO_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GCA_BACKEND_MANAGER_TYPE_INDENT_BACKEND_INFO, GcaBackendManagerIndentBackendInfoPrivate))
enum  {
	GCA_BACKEND_MANAGER_INDENT_BACKEND_INFO_DUMMY_PROPERTY,
	GCA_BACKEND_MANAGER_INDENT_BACKEND_INFO_INFO
};
PeasPluginInfo* gca_backend_manager_indent_backend_info_get_info (GcaBackendManagerIndentBackendInfo* self);
void gca_backend_manager_indent_backend_info_set_info (GcaBackendManagerIndentBackendInfo* self, PeasPluginInfo* value);
static void gca_backend_manager_indent_backend_info_finalize (GObject* obj);
static void _vala_gca_backend_manager_indent_backend_info_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec);
static void _vala_gca_backend_manager_indent_backend_info_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec);
static void gca_backend_manager_finalize (GcaBackendManager* obj);
static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array, gint array_length, GDestroyNotify destroy_func);
static gint _vala_array_length (gpointer array);


static gpointer _g_settings_schema_source_ref0 (gpointer self) {
	return self ? g_settings_schema_source_ref (self) : NULL;
}


static void ___lambda9_ (GcaBackendManager* self) {
	gca_backend_manager_update_language_mapping (self);
}


static void ____lambda9__g_settings_changed (GSettings* _sender, const gchar* key, gpointer self) {
	___lambda9_ ((GcaBackendManager*) self);
}


static GcaBackendManager* gca_backend_manager_construct (GType object_type) {
	GcaBackendManager* self = NULL;
	GeeHashMap* _tmp0_ = NULL;
	GSettingsSchemaSource* source = NULL;
	GSettingsSchemaSource* _tmp1_ = NULL;
	GSettingsSchemaSource* _tmp2_ = NULL;
	gchar* schema = NULL;
	gchar* _tmp3_ = NULL;
	GSettingsSchemaSource* _tmp4_ = NULL;
	const gchar* _tmp5_ = NULL;
	GSettingsSchema* _tmp6_ = NULL;
	GSettingsSchema* _tmp7_ = NULL;
	gboolean _tmp8_ = FALSE;
	GSettings* _tmp11_ = NULL;
	GeeHashMap* _tmp13_ = NULL;
	PeasEngine* _tmp14_ = NULL;
	PeasEngine* _tmp15_ = NULL;
	self = (GcaBackendManager*) g_type_create_instance (object_type);
	_tmp0_ = gee_hash_map_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, g_free, GCA_TYPE_BACKEND, (GBoxedCopyFunc) g_object_ref, g_object_unref, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
	_g_object_unref0 (self->priv->d_backends);
	self->priv->d_backends = _tmp0_;
	_g_object_unref0 (self->priv->d_settings);
	self->priv->d_settings = NULL;
	_tmp1_ = g_settings_schema_source_get_default ();
	_tmp2_ = _g_settings_schema_source_ref0 (_tmp1_);
	source = _tmp2_;
	_tmp3_ = g_strdup ("org.gnome.codeassistance");
	schema = _tmp3_;
	_tmp4_ = source;
	_tmp5_ = schema;
	_tmp6_ = g_settings_schema_source_lookup (_tmp4_, _tmp5_, TRUE);
	_tmp7_ = _tmp6_;
	_tmp8_ = _tmp7_ != NULL;
	_g_settings_schema_unref0 (_tmp7_);
	if (_tmp8_) {
		const gchar* _tmp9_ = NULL;
		GSettings* _tmp10_ = NULL;
		_tmp9_ = schema;
		_tmp10_ = g_settings_new (_tmp9_);
		_g_object_unref0 (self->priv->d_settings);
		self->priv->d_settings = _tmp10_;
	}
	gca_backend_manager_update_language_mapping (self);
	_tmp11_ = self->priv->d_settings;
	if (_tmp11_ != NULL) {
		GSettings* _tmp12_ = NULL;
		_tmp12_ = self->priv->d_settings;
		g_signal_connect (_tmp12_, "changed::language-mapping", (GCallback) ____lambda9__g_settings_changed, self);
	}
	_tmp13_ = gee_hash_map_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, g_free, GCA_BACKEND_MANAGER_TYPE_INDENT_BACKEND_INFO, (GBoxedCopyFunc) g_object_ref, g_object_unref, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
	_g_object_unref0 (self->priv->d_indent_backends);
	self->priv->d_indent_backends = _tmp13_;
	_tmp14_ = peas_engine_new ();
	_g_object_unref0 (self->priv->d_engine);
	self->priv->d_engine = _tmp14_;
	_tmp15_ = self->priv->d_engine;
	peas_engine_add_search_path (_tmp15_, GCA_INDENT_BACKENDS_DIR, GCA_INDENT_BACKENDS_DATA_DIR);
	gca_backend_manager_register_backends (self);
	_g_free0 (schema);
	_g_settings_schema_source_unref0 (source);
	return self;
}


static GcaBackendManager* gca_backend_manager_new (void) {
	return gca_backend_manager_construct (GCA_TYPE_BACKEND_MANAGER);
}


static PeasPluginInfo* _vala_PeasPluginInfo_copy (PeasPluginInfo* self) {
	return g_boxed_copy (peas_plugin_info_get_type (), self);
}


static gpointer __vala_PeasPluginInfo_copy0 (gpointer self) {
	return self ? _vala_PeasPluginInfo_copy (self) : NULL;
}


static void _vala_PeasPluginInfo_free (PeasPluginInfo* self) {
	g_boxed_free (peas_plugin_info_get_type (), self);
}


static void gca_backend_manager_register_backends (GcaBackendManager* self) {
	PeasEngine* _tmp0_ = NULL;
	GList* _tmp1_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->d_engine;
	_tmp1_ = peas_engine_get_plugin_list (_tmp0_);
	{
		GList* info_collection = NULL;
		GList* info_it = NULL;
		info_collection = _tmp1_;
		for (info_it = info_collection; info_it != NULL; info_it = info_it->next) {
			PeasPluginInfo* _tmp2_ = NULL;
			PeasPluginInfo* info = NULL;
			_tmp2_ = __vala_PeasPluginInfo_copy0 ((PeasPluginInfo*) info_it->data);
			info = _tmp2_;
			{
				gchar* langs = NULL;
				PeasPluginInfo* _tmp3_ = NULL;
				const gchar* _tmp4_ = NULL;
				gchar* _tmp5_ = NULL;
				const gchar* _tmp6_ = NULL;
				PeasEngine* _tmp7_ = NULL;
				PeasPluginInfo* _tmp8_ = NULL;
				GcaBackendManagerIndentBackendInfo* binfo = NULL;
				PeasPluginInfo* _tmp9_ = NULL;
				GcaBackendManagerIndentBackendInfo* _tmp10_ = NULL;
				const gchar* _tmp11_ = NULL;
				gchar** _tmp12_ = NULL;
				gchar** _tmp13_ = NULL;
				_tmp3_ = info;
				_tmp4_ = peas_plugin_info_get_external_data (_tmp3_, "Languages");
				_tmp5_ = g_strdup (_tmp4_);
				langs = _tmp5_;
				_tmp6_ = langs;
				if (_tmp6_ == NULL) {
					_g_free0 (langs);
					__vala_PeasPluginInfo_free0 (info);
					continue;
				}
				_tmp7_ = self->priv->d_engine;
				_tmp8_ = info;
				g_signal_emit_by_name (_tmp7_, "load-plugin", _tmp8_);
				_tmp9_ = info;
				_tmp10_ = gca_backend_manager_indent_backend_info_new (_tmp9_);
				binfo = _tmp10_;
				_tmp11_ = langs;
				_tmp13_ = _tmp12_ = g_strsplit (_tmp11_, ",", 0);
				{
					gchar** lang_collection = NULL;
					gint lang_collection_length1 = 0;
					gint _lang_collection_size_ = 0;
					gint lang_it = 0;
					lang_collection = _tmp13_;
					lang_collection_length1 = _vala_array_length (_tmp12_);
					for (lang_it = 0; lang_it < _vala_array_length (_tmp12_); lang_it = lang_it + 1) {
						gchar* _tmp14_ = NULL;
						gchar* lang = NULL;
						_tmp14_ = g_strdup (lang_collection[lang_it]);
						lang = _tmp14_;
						{
							GeeHashMap* _tmp15_ = NULL;
							const gchar* _tmp16_ = NULL;
							GcaBackendManagerIndentBackendInfo* _tmp17_ = NULL;
							_tmp15_ = self->priv->d_indent_backends;
							_tmp16_ = lang;
							_tmp17_ = binfo;
							gee_abstract_map_set ((GeeAbstractMap*) _tmp15_, _tmp16_, _tmp17_);
							_g_free0 (lang);
						}
					}
					lang_collection = (_vala_array_free (lang_collection, lang_collection_length1, (GDestroyNotify) g_free), NULL);
				}
				_g_object_unref0 (binfo);
				_g_free0 (langs);
				__vala_PeasPluginInfo_free0 (info);
			}
		}
	}
}


static void gca_backend_manager_update_language_mapping (GcaBackendManager* self) {
	GeeHashMap* _tmp0_ = NULL;
	GSettings* _tmp1_ = NULL;
	GVariant* mapping = NULL;
	GSettings* _tmp5_ = NULL;
	GVariant* _tmp6_ = NULL;
	GVariant* _tmp7_ = NULL;
	GVariantIter* iter = NULL;
	GVariant* _tmp8_ = NULL;
	GVariantIter* _tmp9_ = NULL;
	gchar* key = NULL;
	gchar* val = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = gee_hash_map_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, g_free, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, g_free, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
	_g_object_unref0 (self->priv->d_language_mapping);
	self->priv->d_language_mapping = _tmp0_;
	_tmp1_ = self->priv->d_settings;
	if (_tmp1_ == NULL) {
		GeeHashMap* _tmp2_ = NULL;
		GeeHashMap* _tmp3_ = NULL;
		GeeHashMap* _tmp4_ = NULL;
		_tmp2_ = self->priv->d_language_mapping;
		gee_abstract_map_set ((GeeAbstractMap*) _tmp2_, "cpp", "c");
		_tmp3_ = self->priv->d_language_mapping;
		gee_abstract_map_set ((GeeAbstractMap*) _tmp3_, "chdr", "c");
		_tmp4_ = self->priv->d_language_mapping;
		gee_abstract_map_set ((GeeAbstractMap*) _tmp4_, "objc", "c");
		return;
	}
	_tmp5_ = self->priv->d_settings;
	_tmp6_ = g_settings_get_value (_tmp5_, "language-mapping");
	mapping = _tmp6_;
	_tmp7_ = mapping;
	if (_tmp7_ == NULL) {
		_g_variant_unref0 (mapping);
		return;
	}
	_tmp8_ = mapping;
	_tmp9_ = g_variant_iter_new (_tmp8_);
	iter = _tmp9_;
	key = NULL;
	val = NULL;
	while (TRUE) {
		GVariantIter* _tmp10_ = NULL;
		gboolean _tmp11_ = FALSE;
		GeeHashMap* _tmp12_ = NULL;
		const gchar* _tmp13_ = NULL;
		const gchar* _tmp14_ = NULL;
		_tmp10_ = iter;
		_tmp11_ = g_variant_iter_next (_tmp10_, "{ss}", &key, &val, NULL);
		if (!_tmp11_) {
			break;
		}
		_tmp12_ = self->priv->d_language_mapping;
		_tmp13_ = key;
		_tmp14_ = val;
		gee_abstract_map_set ((GeeAbstractMap*) _tmp12_, _tmp13_, _tmp14_);
	}
	_g_free0 (val);
	_g_free0 (key);
	_g_variant_iter_free0 (iter);
	_g_variant_unref0 (mapping);
}


static void gca_backend_manager_backend_data_free (gpointer _data) {
	GcaBackendManagerBackendData* _data_;
	_data_ = _data;
	_g_free0 (_data_->language);
	_g_object_unref0 (_data_->result);
	_gca_backend_manager_unref0 (_data_->self);
	g_slice_free (GcaBackendManagerBackendData, _data_);
}


static gpointer _gca_backend_manager_ref0 (gpointer self) {
	return self ? gca_backend_manager_ref (self) : NULL;
}


void gca_backend_manager_backend (GcaBackendManager* self, const gchar* language, GAsyncReadyCallback _callback_, gpointer _user_data_) {
	GcaBackendManagerBackendData* _data_;
	GcaBackendManager* _tmp0_ = NULL;
	const gchar* _tmp1_ = NULL;
	gchar* _tmp2_ = NULL;
	_data_ = g_slice_new0 (GcaBackendManagerBackendData);
	_data_->_async_result = g_simple_async_result_new (NULL, _callback_, _user_data_, gca_backend_manager_backend);
	g_simple_async_result_set_op_res_gpointer (_data_->_async_result, _data_, gca_backend_manager_backend_data_free);
	_tmp0_ = _gca_backend_manager_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = language;
	_tmp2_ = g_strdup (_tmp1_);
	_g_free0 (_data_->language);
	_data_->language = _tmp2_;
	gca_backend_manager_backend_co (_data_);
}


GcaBackend* gca_backend_manager_backend_finish (GcaBackendManager* self, GAsyncResult* _res_) {
	GcaBackend* result;
	GcaBackendManagerBackendData* _data_;
	_data_ = g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (_res_));
	result = _data_->result;
	_data_->result = NULL;
	return result;
}


static void gca_backend_manager_backend_ready (GObject* source_object, GAsyncResult* _res_, gpointer _user_data_) {
	GcaBackendManagerBackendData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	gca_backend_manager_backend_co (_data_);
}


static gboolean gca_backend_manager_backend_co (GcaBackendManagerBackendData* _data_) {
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = NULL;
	_data_->_tmp0_ = _data_->language;
	_data_->_tmp1_ = NULL;
	_data_->_tmp1_ = g_strdup (_data_->_tmp0_);
	_data_->lang = _data_->_tmp1_;
	_data_->_tmp2_ = NULL;
	_data_->_tmp2_ = _data_->self->priv->d_language_mapping;
	_data_->_tmp3_ = NULL;
	_data_->_tmp3_ = _data_->language;
	_data_->_tmp4_ = FALSE;
	_data_->_tmp4_ = gee_abstract_map_has_key ((GeeAbstractMap*) _data_->_tmp2_, _data_->_tmp3_);
	if (_data_->_tmp4_) {
		_data_->_tmp5_ = NULL;
		_data_->_tmp5_ = _data_->self->priv->d_language_mapping;
		_data_->_tmp6_ = NULL;
		_data_->_tmp6_ = _data_->language;
		_data_->_tmp7_ = NULL;
		_data_->_tmp7_ = gee_abstract_map_get ((GeeAbstractMap*) _data_->_tmp5_, _data_->_tmp6_);
		_g_free0 (_data_->lang);
		_data_->lang = (gchar*) _data_->_tmp7_;
	}
	_data_->_tmp8_ = NULL;
	_data_->_tmp8_ = _data_->self->priv->d_backends;
	_data_->_tmp9_ = NULL;
	_data_->_tmp9_ = _data_->lang;
	_data_->_tmp10_ = FALSE;
	_data_->_tmp10_ = gee_abstract_map_has_key ((GeeAbstractMap*) _data_->_tmp8_, _data_->_tmp9_);
	if (_data_->_tmp10_) {
		_data_->_tmp11_ = NULL;
		_data_->_tmp11_ = _data_->self->priv->d_backends;
		_data_->_tmp12_ = NULL;
		_data_->_tmp12_ = _data_->lang;
		_data_->_tmp13_ = NULL;
		_data_->_tmp13_ = gee_abstract_map_get ((GeeAbstractMap*) _data_->_tmp11_, _data_->_tmp12_);
		_data_->result = (GcaBackend*) _data_->_tmp13_;
		_g_free0 (_data_->lang);
		if (_data_->_state_ == 0) {
			g_simple_async_result_complete_in_idle (_data_->_async_result);
		} else {
			g_simple_async_result_complete (_data_->_async_result);
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	{
		_data_->_tmp15_ = NULL;
		_data_->_tmp15_ = _data_->lang;
		_data_->_state_ = 1;
		gca_backend_create (_data_->_tmp15_, gca_backend_manager_backend_ready, _data_);
		return FALSE;
		_state_1:
		_data_->_tmp16_ = NULL;
		_data_->_tmp16_ = gca_backend_create_finish (_data_->_res_, &_data_->_inner_error_);
		_data_->_tmp14_ = _data_->_tmp16_;
		if (G_UNLIKELY (_data_->_inner_error_ != NULL)) {
			goto __catch13_g_error;
		}
		_data_->_tmp17_ = NULL;
		_data_->_tmp17_ = _data_->_tmp14_;
		_data_->_tmp14_ = NULL;
		_g_object_unref0 (_data_->backend);
		_data_->backend = _data_->_tmp17_;
		_g_object_unref0 (_data_->_tmp14_);
	}
	goto __finally13;
	__catch13_g_error:
	{
		_data_->e = _data_->_inner_error_;
		_data_->_inner_error_ = NULL;
		_data_->_tmp18_ = NULL;
		_data_->_tmp18_ = _data_->e;
		_data_->_tmp19_ = NULL;
		_data_->_tmp19_ = _data_->_tmp18_->message;
		gca_log_debug ("gca-backend-manager.vala:149: Failed to obtain backend: %s\n", _data_->_tmp19_);
		_g_object_unref0 (_data_->backend);
		_data_->backend = NULL;
		_g_error_free0 (_data_->e);
	}
	__finally13:
	if (G_UNLIKELY (_data_->_inner_error_ != NULL)) {
		_g_object_unref0 (_data_->backend);
		_g_free0 (_data_->lang);
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error_->message, g_quark_to_string (_data_->_inner_error_->domain), _data_->_inner_error_->code);
		g_clear_error (&_data_->_inner_error_);
		return FALSE;
	}
	_data_->_tmp20_ = NULL;
	_data_->_tmp20_ = _data_->self->priv->d_backends;
	_data_->_tmp21_ = NULL;
	_data_->_tmp21_ = _data_->lang;
	_data_->_tmp22_ = NULL;
	_data_->_tmp22_ = _data_->backend;
	gee_abstract_map_set ((GeeAbstractMap*) _data_->_tmp20_, _data_->_tmp21_, _data_->_tmp22_);
	_data_->result = _data_->backend;
	_g_free0 (_data_->lang);
	if (_data_->_state_ == 0) {
		g_simple_async_result_complete_in_idle (_data_->_async_result);
	} else {
		g_simple_async_result_complete (_data_->_async_result);
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
	_g_object_unref0 (_data_->backend);
	_g_free0 (_data_->lang);
	if (_data_->_state_ == 0) {
		g_simple_async_result_complete_in_idle (_data_->_async_result);
	} else {
		g_simple_async_result_complete (_data_->_async_result);
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}


GcaBackendManagerIndentBackendInfo* gca_backend_manager_indent_backend_info (GcaBackendManager* self, const gchar* language) {
	GcaBackendManagerIndentBackendInfo* result = NULL;
	GeeHashMap* _tmp0_ = NULL;
	const gchar* _tmp1_ = NULL;
	gboolean _tmp2_ = FALSE;
	GeeHashMap* _tmp3_ = NULL;
	const gchar* _tmp4_ = NULL;
	gpointer _tmp5_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (language != NULL, NULL);
	_tmp0_ = self->priv->d_indent_backends;
	_tmp1_ = language;
	_tmp2_ = gee_abstract_map_has_key ((GeeAbstractMap*) _tmp0_, _tmp1_);
	if (!_tmp2_) {
		result = NULL;
		return result;
	}
	_tmp3_ = self->priv->d_indent_backends;
	_tmp4_ = language;
	_tmp5_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp3_, _tmp4_);
	result = (GcaBackendManagerIndentBackendInfo*) _tmp5_;
	return result;
}


GcaBackendManager* gca_backend_manager_get_instance (void) {
	GcaBackendManager* result;
	GcaBackendManager* _tmp0_ = NULL;
	GcaBackendManager* _tmp2_ = NULL;
	_tmp0_ = gca_backend_manager_s_instance;
	if (_tmp0_ == NULL) {
		GcaBackendManager* _tmp1_ = NULL;
		_tmp1_ = gca_backend_manager_new ();
		_gca_backend_manager_unref0 (gca_backend_manager_s_instance);
		gca_backend_manager_s_instance = _tmp1_;
	}
	_tmp2_ = gca_backend_manager_s_instance;
	result = _tmp2_;
	return result;
}


GcaBackendManagerIndentBackendInfo* gca_backend_manager_indent_backend_info_construct (GType object_type, PeasPluginInfo* info) {
	GcaBackendManagerIndentBackendInfo * self = NULL;
	PeasPluginInfo* _tmp0_ = NULL;
	g_return_val_if_fail (info != NULL, NULL);
	_tmp0_ = info;
	self = (GcaBackendManagerIndentBackendInfo*) g_object_new (object_type, "info", _tmp0_, NULL);
	return self;
}


GcaBackendManagerIndentBackendInfo* gca_backend_manager_indent_backend_info_new (PeasPluginInfo* info) {
	return gca_backend_manager_indent_backend_info_construct (GCA_BACKEND_MANAGER_TYPE_INDENT_BACKEND_INFO, info);
}


PeasPluginInfo* gca_backend_manager_indent_backend_info_get_info (GcaBackendManagerIndentBackendInfo* self) {
	PeasPluginInfo* result;
	PeasPluginInfo* _tmp0_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_info;
	result = _tmp0_;
	return result;
}


void gca_backend_manager_indent_backend_info_set_info (GcaBackendManagerIndentBackendInfo* self, PeasPluginInfo* value) {
	PeasPluginInfo* _tmp0_ = NULL;
	PeasPluginInfo* _tmp1_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = value;
	_tmp1_ = __vala_PeasPluginInfo_copy0 (_tmp0_);
	__vala_PeasPluginInfo_free0 (self->priv->_info);
	self->priv->_info = _tmp1_;
	g_object_notify ((GObject *) self, "info");
}


static void gca_backend_manager_indent_backend_info_class_init (GcaBackendManagerIndentBackendInfoClass * klass) {
	gca_backend_manager_indent_backend_info_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (GcaBackendManagerIndentBackendInfoPrivate));
	G_OBJECT_CLASS (klass)->get_property = _vala_gca_backend_manager_indent_backend_info_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_gca_backend_manager_indent_backend_info_set_property;
	G_OBJECT_CLASS (klass)->finalize = gca_backend_manager_indent_backend_info_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), GCA_BACKEND_MANAGER_INDENT_BACKEND_INFO_INFO, g_param_spec_boxed ("info", "info", "info", peas_plugin_info_get_type (), G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE));
}


static void gca_backend_manager_indent_backend_info_instance_init (GcaBackendManagerIndentBackendInfo * self) {
	self->priv = GCA_BACKEND_MANAGER_INDENT_BACKEND_INFO_GET_PRIVATE (self);
}


static void gca_backend_manager_indent_backend_info_finalize (GObject* obj) {
	GcaBackendManagerIndentBackendInfo * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GCA_BACKEND_MANAGER_TYPE_INDENT_BACKEND_INFO, GcaBackendManagerIndentBackendInfo);
	__vala_PeasPluginInfo_free0 (self->priv->_info);
	G_OBJECT_CLASS (gca_backend_manager_indent_backend_info_parent_class)->finalize (obj);
}


GType gca_backend_manager_indent_backend_info_get_type (void) {
	static volatile gsize gca_backend_manager_indent_backend_info_type_id__volatile = 0;
	if (g_once_init_enter (&gca_backend_manager_indent_backend_info_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (GcaBackendManagerIndentBackendInfoClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) gca_backend_manager_indent_backend_info_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GcaBackendManagerIndentBackendInfo), 0, (GInstanceInitFunc) gca_backend_manager_indent_backend_info_instance_init, NULL };
		GType gca_backend_manager_indent_backend_info_type_id;
		gca_backend_manager_indent_backend_info_type_id = g_type_register_static (G_TYPE_OBJECT, "GcaBackendManagerIndentBackendInfo", &g_define_type_info, 0);
		g_once_init_leave (&gca_backend_manager_indent_backend_info_type_id__volatile, gca_backend_manager_indent_backend_info_type_id);
	}
	return gca_backend_manager_indent_backend_info_type_id__volatile;
}


static void _vala_gca_backend_manager_indent_backend_info_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec) {
	GcaBackendManagerIndentBackendInfo * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GCA_BACKEND_MANAGER_TYPE_INDENT_BACKEND_INFO, GcaBackendManagerIndentBackendInfo);
	switch (property_id) {
		case GCA_BACKEND_MANAGER_INDENT_BACKEND_INFO_INFO:
		g_value_set_boxed (value, gca_backend_manager_indent_backend_info_get_info (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}


static void _vala_gca_backend_manager_indent_backend_info_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec) {
	GcaBackendManagerIndentBackendInfo * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GCA_BACKEND_MANAGER_TYPE_INDENT_BACKEND_INFO, GcaBackendManagerIndentBackendInfo);
	switch (property_id) {
		case GCA_BACKEND_MANAGER_INDENT_BACKEND_INFO_INFO:
		gca_backend_manager_indent_backend_info_set_info (self, g_value_get_boxed (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}


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


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


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


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


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


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


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


void gca_value_set_backend_manager (GValue* value, gpointer v_object) {
	GcaBackendManager* old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, GCA_TYPE_BACKEND_MANAGER));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, GCA_TYPE_BACKEND_MANAGER));
		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;
		gca_backend_manager_ref (value->data[0].v_pointer);
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		gca_backend_manager_unref (old);
	}
}


void gca_value_take_backend_manager (GValue* value, gpointer v_object) {
	GcaBackendManager* old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, GCA_TYPE_BACKEND_MANAGER));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, GCA_TYPE_BACKEND_MANAGER));
		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) {
		gca_backend_manager_unref (old);
	}
}


static void gca_backend_manager_class_init (GcaBackendManagerClass * klass) {
	gca_backend_manager_parent_class = g_type_class_peek_parent (klass);
	((GcaBackendManagerClass *) klass)->finalize = gca_backend_manager_finalize;
	g_type_class_add_private (klass, sizeof (GcaBackendManagerPrivate));
}


static void gca_backend_manager_instance_init (GcaBackendManager * self) {
	self->priv = GCA_BACKEND_MANAGER_GET_PRIVATE (self);
	self->ref_count = 1;
}


static void gca_backend_manager_finalize (GcaBackendManager* obj) {
	GcaBackendManager * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GCA_TYPE_BACKEND_MANAGER, GcaBackendManager);
	g_signal_handlers_destroy (self);
	_g_object_unref0 (self->priv->d_backends);
	_g_object_unref0 (self->priv->d_language_mapping);
	_g_object_unref0 (self->priv->d_settings);
	_g_object_unref0 (self->priv->d_indent_backends);
	_g_object_unref0 (self->priv->d_engine);
}


GType gca_backend_manager_get_type (void) {
	static volatile gsize gca_backend_manager_type_id__volatile = 0;
	if (g_once_init_enter (&gca_backend_manager_type_id__volatile)) {
		static const GTypeValueTable g_define_type_value_table = { gca_value_backend_manager_init, gca_value_backend_manager_free_value, gca_value_backend_manager_copy_value, gca_value_backend_manager_peek_pointer, "p", gca_value_backend_manager_collect_value, "p", gca_value_backend_manager_lcopy_value };
		static const GTypeInfo g_define_type_info = { sizeof (GcaBackendManagerClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) gca_backend_manager_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GcaBackendManager), 0, (GInstanceInitFunc) gca_backend_manager_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 gca_backend_manager_type_id;
		gca_backend_manager_type_id = g_type_register_fundamental (g_type_fundamental_next (), "GcaBackendManager", &g_define_type_info, &g_define_type_fundamental_info, 0);
		g_once_init_leave (&gca_backend_manager_type_id__volatile, gca_backend_manager_type_id);
	}
	return gca_backend_manager_type_id__volatile;
}


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


void gca_backend_manager_unref (gpointer instance) {
	GcaBackendManager* self;
	self = instance;
	if (g_atomic_int_dec_and_test (&self->ref_count)) {
		GCA_BACKEND_MANAGER_GET_CLASS (self)->finalize (self);
		g_type_free_instance ((GTypeInstance *) self);
	}
}


static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func) {
	if ((array != NULL) && (destroy_func != NULL)) {
		int i;
		for (i = 0; i < array_length; i = i + 1) {
			if (((gpointer*) array)[i] != NULL) {
				destroy_func (((gpointer*) array)[i]);
			}
		}
	}
}


static void _vala_array_free (gpointer array, gint array_length, GDestroyNotify destroy_func) {
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}


static gint _vala_array_length (gpointer array) {
	int length;
	length = 0;
	if (array) {
		while (((gpointer*) array)[length]) {
			length++;
		}
	}
	return length;
}



