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

/*
 * Copyright (C) 2010 Collabora Ltd.
 *
 * This library 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 library 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, see <http://www.gnu.org/licenses/>.
 *
 * Authors:
 *       Philip Withnall <philip.withnall@collabora.co.uk>
 */

#include <glib.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <gee.h>
#include <stdio.h>
#include <stdarg.h>


#define FOLKS_TYPE_DEBUG (folks_debug_get_type ())
#define FOLKS_DEBUG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), FOLKS_TYPE_DEBUG, FolksDebug))
#define FOLKS_DEBUG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), FOLKS_TYPE_DEBUG, FolksDebugClass))
#define FOLKS_IS_DEBUG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), FOLKS_TYPE_DEBUG))
#define FOLKS_IS_DEBUG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), FOLKS_TYPE_DEBUG))
#define FOLKS_DEBUG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), FOLKS_TYPE_DEBUG, FolksDebugClass))

typedef struct _FolksDebug FolksDebug;
typedef struct _FolksDebugClass FolksDebugClass;
typedef struct _FolksDebugPrivate FolksDebugPrivate;

#define FOLKS_DEBUG_TYPE_DOMAINS (folks_debug_domains_get_type ())
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))

#define FOLKS_DEBUG_TYPE_KEY_VALUE_PAIR (folks_debug_key_value_pair_get_type ())
typedef struct _FolksDebugKeyValuePair FolksDebugKeyValuePair;

struct _FolksDebug {
	GObject parent_instance;
	FolksDebugPrivate * priv;
};

struct _FolksDebugClass {
	GObjectClass parent_class;
};

struct _FolksDebugPrivate {
	GeeHashSet* _domains;
	GStaticRecMutex __lock__domains;
	gboolean _all;
	guint _indentation;
	gchar* _indentation_string;
	gboolean _colour_enabled;
	GStaticRecMutex __lock__colour_enabled;
	gboolean _debug_output_enabled;
	GStaticRecMutex __lock__debug_output_enabled;
};

typedef enum  {
	FOLKS_DEBUG_DOMAINS_CORE = 1 << 0,
	FOLKS_DEBUG_DOMAINS_TELEPATHY_BACKEND = 1 << 1,
	FOLKS_DEBUG_DOMAINS_KEY_FILE_BACKEND = 1 << 2
} FolksDebugDomains;

struct _FolksDebugKeyValuePair {
	gchar* key;
	gchar* val;
};


static gpointer folks_debug_parent_class = NULL;
static FolksDebug* folks_debug__instance;
static GStaticRecMutex __lock_folks_debug__instance = {0};
static FolksDebug* folks_debug__instance = NULL;

void g_log (const gchar* log_domain, GLogLevelFlags log_level, const gchar* format, ...);
GType folks_debug_get_type (void) G_GNUC_CONST;
#define FOLKS_DEBUG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), FOLKS_TYPE_DEBUG, FolksDebugPrivate))
enum  {
	FOLKS_DEBUG_DUMMY_PROPERTY,
	FOLKS_DEBUG_COLOUR_ENABLED,
	FOLKS_DEBUG_DEBUG_OUTPUT_ENABLED
};
static GType folks_debug_domains_get_type (void) G_GNUC_UNUSED;
#define FOLKS_DEBUG_STATUS_LOG_DOMAIN "folks-status"
static void _folks_debug_print_status_log_handler_cb (FolksDebug* self, const gchar* log_domain, GLogLevelFlags log_levels, const gchar* message);
static void _folks_debug_log_handler_cb (FolksDebug* self, const gchar* log_domain, GLogLevelFlags log_levels, const gchar* message);
gboolean folks_debug_get_debug_output_enabled (FolksDebug* self);
void _folks_debug_register_domain (FolksDebug* self, const gchar* domain);
static void __folks_debug_log_handler_cb_glog_func (const gchar* log_domain, GLogLevelFlags log_levels, const gchar* message, gpointer self);
static void _lambda0_ (const gchar* domain_arg, GLogLevelFlags flags, const gchar* message, FolksDebug* self);
static void __lambda0__glog_func (const gchar* log_domain, GLogLevelFlags log_levels, const gchar* message, gpointer self);
FolksDebug* folks_debug_dup (void);
static FolksDebug* folks_debug_new (void);
static FolksDebug* folks_debug_construct (GType object_type);
FolksDebug* folks_debug_dup_with_flags (const gchar* debug_flags, gboolean colour_enabled);
void folks_debug_set_colour_enabled (FolksDebug* self, gboolean value);
static void __folks_debug_print_status_log_handler_cb_glog_func (const gchar* log_domain, GLogLevelFlags log_levels, const gchar* message, gpointer self);
void folks_debug_emit_print_status (FolksDebug* self);
void folks_debug_indent (FolksDebug* self);
void folks_debug_unindent (FolksDebug* self);
void folks_debug_print_line (FolksDebug* self, const gchar* domain, GLogLevelFlags level, const gchar* format, ...);
void folks_debug_print_heading (FolksDebug* self, const gchar* domain, GLogLevelFlags level, const gchar* format, ...);
gboolean folks_debug_get_colour_enabled (FolksDebug* self);
static gchar* _folks_debug_format_nullable_string (FolksDebug* self, const gchar* input);
void folks_debug_print_key_value_pairs (FolksDebug* self, const gchar* domain, GLogLevelFlags level, ...);
static GType folks_debug_key_value_pair_get_type (void) G_GNUC_CONST G_GNUC_UNUSED;
static FolksDebugKeyValuePair* folks_debug_key_value_pair_dup (const FolksDebugKeyValuePair* self);
static void folks_debug_key_value_pair_free (FolksDebugKeyValuePair* self);
static void folks_debug_key_value_pair_copy (const FolksDebugKeyValuePair* self, FolksDebugKeyValuePair* dest);
static void folks_debug_key_value_pair_destroy (FolksDebugKeyValuePair* self);
static void _vala_array_add1 (FolksDebugKeyValuePair** array, int* length, int* size, const FolksDebugKeyValuePair* value);
static void _vala_FolksDebugKeyValuePair_array_free (FolksDebugKeyValuePair* array, gint array_length);
void folks_debug_set_debug_output_enabled (FolksDebug* self, gboolean value);
static void folks_debug_finalize (GObject* obj);
static void _vala_folks_debug_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec);
static void _vala_folks_debug_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec);
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 GType folks_debug_domains_get_type (void) {
	static volatile gsize folks_debug_domains_type_id__volatile = 0;
	if (g_once_init_enter (&folks_debug_domains_type_id__volatile)) {
		static const GEnumValue values[] = {{FOLKS_DEBUG_DOMAINS_CORE, "FOLKS_DEBUG_DOMAINS_CORE", "core"}, {FOLKS_DEBUG_DOMAINS_TELEPATHY_BACKEND, "FOLKS_DEBUG_DOMAINS_TELEPATHY_BACKEND", "telepathy-backend"}, {FOLKS_DEBUG_DOMAINS_KEY_FILE_BACKEND, "FOLKS_DEBUG_DOMAINS_KEY_FILE_BACKEND", "key-file-backend"}, {0, NULL, NULL}};
		GType folks_debug_domains_type_id;
		folks_debug_domains_type_id = g_enum_register_static ("FolksDebugDomains", values);
		g_once_init_leave (&folks_debug_domains_type_id__volatile, folks_debug_domains_type_id);
	}
	return folks_debug_domains_type_id__volatile;
}


static void _folks_debug_print_status_log_handler_cb (FolksDebug* self, const gchar* log_domain, GLogLevelFlags log_levels, const gchar* message) {
	g_return_if_fail (self != NULL);
	g_return_if_fail (message != NULL);
	fprintf (stdout, "%s\n", message);
}


static void _folks_debug_log_handler_cb (FolksDebug* self, const gchar* log_domain, GLogLevelFlags log_levels, const gchar* message) {
	gboolean _tmp0_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (message != NULL);
	_tmp0_ = folks_debug_get_debug_output_enabled (self);
	if (_tmp0_ == FALSE) {
		return;
	}
	g_log_default_handler (log_domain, log_levels, message, NULL);
}


static void __folks_debug_log_handler_cb_glog_func (const gchar* log_domain, GLogLevelFlags log_levels, const gchar* message, gpointer self) {
	_folks_debug_log_handler_cb (self, log_domain, log_levels, message);
}


static void _lambda0_ (const gchar* domain_arg, GLogLevelFlags flags, const gchar* message, FolksDebug* self) {
	g_return_if_fail (message != NULL);
}


static void __lambda0__glog_func (const gchar* log_domain, GLogLevelFlags log_levels, const gchar* message, gpointer self) {
	_lambda0_ (log_domain, log_levels, message, self);
}


void _folks_debug_register_domain (FolksDebug* self, const gchar* domain) {
	GError * _inner_error_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (domain != NULL);
	{
		gboolean _tmp0_ = FALSE;
		g_static_rec_mutex_lock (&self->priv->__lock__domains);
		if (self->priv->_all) {
			_tmp0_ = TRUE;
		} else {
			gchar* _tmp1_ = NULL;
			gchar* _tmp2_;
			gboolean _tmp3_;
			_tmp1_ = g_utf8_strdown (domain, (gssize) (-1));
			_tmp2_ = _tmp1_;
			_tmp3_ = gee_abstract_collection_contains ((GeeAbstractCollection*) self->priv->_domains, _tmp2_);
			_tmp0_ = _tmp3_;
			_g_free0 (_tmp2_);
		}
		if (_tmp0_) {
			g_log_set_handler (domain, G_LOG_LEVEL_MASK, __folks_debug_log_handler_cb_glog_func, self);
			g_static_rec_mutex_unlock (&self->priv->__lock__domains);
			return;
		}
		__finally15:
		g_static_rec_mutex_unlock (&self->priv->__lock__domains);
		if (_inner_error_ != NULL) {
			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_log_set_handler (domain, G_LOG_LEVEL_DEBUG, __lambda0__glog_func, self);
}


/**
   * Create or return the singleton {@link Debug} class instance.
   * If the instance doesn't exist already, it will be created with no debug
   * domains enabled.
   *
   * This function is thread-safe.
   *
   * @return  Singleton {@link Debug} instance
   * @since 0.5.1
   */
static gpointer _g_object_ref0 (gpointer self) {
	return self ? g_object_ref (self) : NULL;
}


FolksDebug* folks_debug_dup (void) {
	FolksDebug* result = NULL;
	GError * _inner_error_ = NULL;
	{
		FolksDebug* _tmp0_;
		FolksDebug* retval;
		g_static_rec_mutex_lock (&__lock_folks_debug__instance);
		_tmp0_ = _g_object_ref0 (folks_debug__instance);
		retval = _tmp0_;
		if (retval == NULL) {
			FolksDebug* _tmp1_ = NULL;
			_tmp1_ = folks_debug_new ();
			_g_object_unref0 (retval);
			retval = _tmp1_;
			folks_debug__instance = retval;
		}
		result = retval;
		g_static_rec_mutex_unlock (&__lock_folks_debug__instance);
		return result;
		_g_object_unref0 (retval);
		__finally16:
		g_static_rec_mutex_unlock (&__lock_folks_debug__instance);
		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 NULL;
	}
}


/**
   * Create or return the singleton {@link Debug} class instance.
   * If the instance doesn't exist already, it will be created with the given
   * set of debug domains enabled. Otherwise, the existing instance will have
   * its set of enabled domains changed to the provided set.
   *
   * @param debug_flags A comma-separated list of debug domains to enable, or
   * null to disable debug output
   * @param colour_enabled Whether debug output should be coloured using
   * terminal escape sequences
   * @return Singleton {@link Debug} instance
   * @since 0.5.1
   */
FolksDebug* folks_debug_dup_with_flags (const gchar* debug_flags, gboolean colour_enabled) {
	FolksDebug* result = NULL;
	FolksDebug* _tmp0_ = NULL;
	FolksDebug* retval;
	GError * _inner_error_ = NULL;
	_tmp0_ = folks_debug_dup ();
	retval = _tmp0_;
	{
		GeeHashSet* _tmp1_ = NULL;
		gboolean _tmp2_ = FALSE;
		g_static_rec_mutex_lock (&retval->priv->__lock__domains);
		retval->priv->_all = FALSE;
		_tmp1_ = gee_hash_set_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, g_free, g_str_hash, g_str_equal);
		_g_object_unref0 (retval->priv->_domains);
		retval->priv->_domains = _tmp1_;
		if (debug_flags != NULL) {
			_tmp2_ = g_strcmp0 (debug_flags, "") != 0;
		} else {
			_tmp2_ = FALSE;
		}
		if (_tmp2_) {
			gchar** _tmp3_;
			gchar** _tmp4_ = NULL;
			gchar** domains_split;
			gint domains_split_length1;
			gint _domains_split_size_;
			_tmp4_ = _tmp3_ = g_strsplit (debug_flags, ",", 0);
			domains_split = _tmp4_;
			domains_split_length1 = _vala_array_length (_tmp3_);
			_domains_split_size_ = _vala_array_length (_tmp3_);
			{
				gchar** domain_collection;
				int domain_collection_length1;
				int domain_it;
				domain_collection = domains_split;
				domain_collection_length1 = domains_split_length1;
				for (domain_it = 0; domain_it < domains_split_length1; domain_it = domain_it + 1) {
					gchar* _tmp5_;
					gchar* domain;
					_tmp5_ = g_strdup (domain_collection[domain_it]);
					domain = _tmp5_;
					{
						gchar* _tmp6_ = NULL;
						gchar* domain_lower;
						gint _tmp7_;
						_tmp6_ = g_utf8_strdown (domain, (gssize) (-1));
						domain_lower = _tmp6_;
						_tmp7_ = g_strcmp0 (domain_lower, "all");
						if (_tmp7_ == 0) {
							retval->priv->_all = TRUE;
						} else {
							gee_abstract_collection_add ((GeeAbstractCollection*) retval->priv->_domains, domain_lower);
						}
						_g_free0 (domain_lower);
						_g_free0 (domain);
					}
				}
			}
			domains_split = (_vala_array_free (domains_split, domains_split_length1, (GDestroyNotify) g_free), NULL);
		}
		__finally17:
		g_static_rec_mutex_unlock (&retval->priv->__lock__domains);
		if (_inner_error_ != NULL) {
			_g_object_unref0 (retval);
			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 NULL;
		}
	}
	folks_debug_set_colour_enabled (retval, colour_enabled);
	result = retval;
	return result;
}


static void __folks_debug_print_status_log_handler_cb_glog_func (const gchar* log_domain, GLogLevelFlags log_levels, const gchar* message, gpointer self) {
	_folks_debug_print_status_log_handler_cb (self, log_domain, log_levels, message);
}


static FolksDebug* folks_debug_construct (GType object_type) {
	FolksDebug * self = NULL;
	self = (FolksDebug*) g_object_new (object_type, NULL);
	g_log_set_handler (FOLKS_DEBUG_STATUS_LOG_DOMAIN, G_LOG_LEVEL_MASK, __folks_debug_print_status_log_handler_cb_glog_func, self);
	return self;
}


static FolksDebug* folks_debug_new (void) {
	return folks_debug_construct (FOLKS_TYPE_DEBUG);
}


/**
   * Causes all significant objects in the library to print their current
   * status to standard output, obeying the options set on this
   * {@link Debug} instance for colouring and other formatting.
   *
   * @since 0.5.1
   */
void folks_debug_emit_print_status (FolksDebug* self) {
	g_return_if_fail (self != NULL);
	g_print ("Dumping status information…\n");
	g_signal_emit_by_name (self, "print-status");
}


/**
   * Increment the indentation level used when printing output through the
   * object.
   *
   * This is intended to be used by backend libraries only.
   *
   * @since 0.5.1
   */
void folks_debug_indent (FolksDebug* self) {
	gchar* _tmp0_ = NULL;
	g_return_if_fail (self != NULL);
	self->priv->_indentation++;
	_tmp0_ = g_strnfill ((gsize) (self->priv->_indentation * 2), ' ');
	_g_free0 (self->priv->_indentation_string);
	self->priv->_indentation_string = _tmp0_;
}


/**
   * Decrement the indentation level used when printing output through the
   * object.
   *
   * This is intended to be used by backend libraries only.
   *
   * @since 0.5.1
   */
void folks_debug_unindent (FolksDebug* self) {
	gchar* _tmp0_ = NULL;
	g_return_if_fail (self != NULL);
	self->priv->_indentation--;
	_tmp0_ = g_strnfill ((gsize) (self->priv->_indentation * 2), ' ');
	_g_free0 (self->priv->_indentation_string);
	self->priv->_indentation_string = _tmp0_;
}


/**
   * Print a debug line with the current indentation level for the specified
   * debug domain.
   *
   * This is intended to be used by backend libraries only.
   *
   * @param domain The debug domain name
   * @param level A set of log level flags for the message
   * @param format A printf-style format string for the heading
   * @param ... Arguments for the format string
   * @since 0.5.1
   */
void folks_debug_print_line (FolksDebug* self, const gchar* domain, GLogLevelFlags level, const gchar* format, ...) {
	va_list valist;
	gchar* _tmp0_ = NULL;
	gchar* output;
	g_return_if_fail (self != NULL);
	g_return_if_fail (domain != NULL);
	g_return_if_fail (format != NULL);
	va_start (valist, format);
	_tmp0_ = g_strdup_vprintf (format, valist);
	output = _tmp0_;
	g_log (domain, level, "%s%s", self->priv->_indentation_string, output);
	_g_free0 (output);
	va_end (valist);
}


/**
   * Print a debug line as a heading. It will be coloured according to the
   * current indentation level so that different levels of headings stand out.
   *
   * This is intended to be used by backend libraries only.
   *
   * @param domain The debug domain name
   * @param level A set of log level flags for the message
   * @param format A printf-style format string for the heading
   * @param ... Arguments for the format string
   * @since 0.5.1
   */
void folks_debug_print_heading (FolksDebug* self, const gchar* domain, GLogLevelFlags level, const gchar* format, ...) {
	static const gint heading_colours[] = {31, 32, 34};
	gchar* _tmp0_;
	gchar* wrapper_format;
	gboolean _tmp1_;
	va_list valist;
	gchar* _tmp4_ = NULL;
	gchar* output;
	g_return_if_fail (self != NULL);
	g_return_if_fail (domain != NULL);
	g_return_if_fail (format != NULL);
	_tmp0_ = g_strdup ("%s");
	wrapper_format = _tmp0_;
	_tmp1_ = folks_debug_get_colour_enabled (self);
	if (_tmp1_ == TRUE) {
		guint _tmp2_;
		guint indentation;
		gchar* _tmp3_ = NULL;
		_tmp2_ = CLAMP (self->priv->_indentation, (guint) 0, (guint) (G_N_ELEMENTS (heading_colours) - 1));
		indentation = _tmp2_;
		_tmp3_ = g_strdup_printf ("\033[1;%im%%s\033[0m", heading_colours[indentation]);
		_g_free0 (wrapper_format);
		wrapper_format = _tmp3_;
	}
	va_start (valist, format);
	_tmp4_ = g_strdup_vprintf (format, valist);
	output = _tmp4_;
	folks_debug_print_line (self, domain, level, wrapper_format, output);
	_g_free0 (output);
	va_end (valist);
	_g_free0 (wrapper_format);
}


static gchar* _folks_debug_format_nullable_string (FolksDebug* self, const gchar* input) {
	gchar* result = NULL;
	gboolean _tmp0_ = FALSE;
	gboolean _tmp1_;
	gchar* _tmp4_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp1_ = folks_debug_get_colour_enabled (self);
	if (_tmp1_ == TRUE) {
		_tmp0_ = input == NULL;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		gchar* _tmp2_;
		_tmp2_ = g_strdup ("\033[1;36m(null)\033[0m");
		result = _tmp2_;
		return result;
	} else {
		if (input == NULL) {
			gchar* _tmp3_;
			_tmp3_ = g_strdup ("(null)");
			result = _tmp3_;
			return result;
		}
	}
	_tmp4_ = g_strdup (input);
	result = _tmp4_;
	return result;
}


/**
   * Print a set of key–value pairs in a table. The width of the key column is
   * automatically set to the width of the longest key. The keys and values
   * must be provided as a null-delimited list of alternating key–value varargs.
   * Values may be null but keys may not.
   *
   * This is intended to be used by backend libraries only.
   *
   * The table will be printed at the current indentation level plus one.
   *
   * @param domain The debug domain name
   * @param level A set of log level flags for the message
   * @param ... Alternating keys and values, terminated with null
   * @since 0.5.1
   */
static void _vala_array_add1 (FolksDebugKeyValuePair** array, int* length, int* size, const FolksDebugKeyValuePair* value) {
	if ((*length) == (*size)) {
		*size = (*size) ? (2 * (*size)) : 4;
		*array = g_renew (FolksDebugKeyValuePair, *array, *size);
	}
	(*array)[(*length)++] = *value;
}


static void _vala_FolksDebugKeyValuePair_array_free (FolksDebugKeyValuePair* array, gint array_length) {
	if (array != NULL) {
		int i;
		for (i = 0; i < array_length; i = i + 1) {
			folks_debug_key_value_pair_destroy (&array[i]);
		}
	}
	g_free (array);
}


void folks_debug_print_key_value_pairs (FolksDebug* self, const gchar* domain, GLogLevelFlags level, ...) {
	va_list valist;
	FolksDebugKeyValuePair* _tmp0_ = NULL;
	FolksDebugKeyValuePair* lines;
	gint lines_length1;
	gint _lines_size_;
	guint max_key_length;
	g_return_if_fail (self != NULL);
	g_return_if_fail (domain != NULL);
	va_start (valist, level);
	_tmp0_ = g_new0 (FolksDebugKeyValuePair, 0);
	lines = _tmp0_;
	lines_length1 = 0;
	_lines_size_ = 0;
	max_key_length = (guint) 0;
	while (TRUE) {
		const gchar* _tmp1_ = NULL;
		gchar* _tmp2_;
		gchar* key;
		const gchar* _tmp3_ = NULL;
		gchar* _tmp4_;
		gchar* val;
		gint _tmp5_;
		guint _tmp6_;
		gchar* _tmp7_;
		gchar* _tmp8_;
		FolksDebugKeyValuePair _tmp9_ = {0};
		FolksDebugKeyValuePair _tmp10_ = {0};
		_tmp1_ = va_arg (valist, gchar*);
		_tmp2_ = g_strdup (_tmp1_);
		key = _tmp2_;
		if (key == NULL) {
			_g_free0 (key);
			break;
		}
		_tmp3_ = va_arg (valist, gchar*);
		_tmp4_ = g_strdup (_tmp3_);
		val = _tmp4_;
		_tmp5_ = strlen (key);
		_tmp6_ = MAX ((guint) _tmp5_, max_key_length);
		max_key_length = _tmp6_;
		_tmp7_ = g_strdup (key);
		_tmp8_ = g_strdup (val);
		memset (&_tmp9_, 0, sizeof (FolksDebugKeyValuePair));
		_tmp9_.key = _tmp7_;
		_tmp9_.val = _tmp8_;
		_tmp10_ = _tmp9_;
		_vala_array_add1 (&lines, &lines_length1, &_lines_size_, &_tmp10_);
		_g_free0 (val);
		_g_free0 (key);
	}
	folks_debug_indent (self);
	{
		FolksDebugKeyValuePair* line_collection;
		int line_collection_length1;
		int line_it;
		line_collection = lines;
		line_collection_length1 = lines_length1;
		for (line_it = 0; line_it < lines_length1; line_it = line_it + 1) {
			FolksDebugKeyValuePair _tmp11_;
			FolksDebugKeyValuePair _tmp12_ = {0};
			FolksDebugKeyValuePair line;
			folks_debug_key_value_pair_copy (&line_collection[line_it], &_tmp12_);
			_tmp11_ = _tmp12_;
			line = _tmp11_;
			{
				gint _tmp13_;
				gchar* _tmp14_ = NULL;
				gchar* padding;
				gchar* _tmp15_ = NULL;
				gchar* _tmp16_;
				_tmp13_ = strlen (line.key);
				_tmp14_ = g_strnfill ((gsize) (max_key_length - _tmp13_), ' ');
				padding = _tmp14_;
				_tmp15_ = _folks_debug_format_nullable_string (self, line.val);
				_tmp16_ = _tmp15_;
				folks_debug_print_line (self, domain, level, "%s: %s%s", line.key, padding, _tmp16_);
				_g_free0 (_tmp16_);
				_g_free0 (padding);
				folks_debug_key_value_pair_destroy (&line);
			}
		}
	}
	folks_debug_unindent (self);
	lines = (_vala_FolksDebugKeyValuePair_array_free (lines, lines_length1), NULL);
	va_end (valist);
}


gboolean folks_debug_get_colour_enabled (FolksDebug* self) {
	gboolean result;
	GError * _inner_error_ = NULL;
	g_return_val_if_fail (self != NULL, FALSE);
	{
		g_static_rec_mutex_lock (&self->priv->__lock__colour_enabled);
		result = self->priv->_colour_enabled;
		g_static_rec_mutex_unlock (&self->priv->__lock__colour_enabled);
		return result;
		__finally18:
		g_static_rec_mutex_unlock (&self->priv->__lock__colour_enabled);
		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 FALSE;
	}
}


void folks_debug_set_colour_enabled (FolksDebug* self, gboolean value) {
	GError * _inner_error_ = NULL;
	g_return_if_fail (self != NULL);
	{
		g_static_rec_mutex_lock (&self->priv->__lock__colour_enabled);
		self->priv->_colour_enabled = value;
		__finally19:
		g_static_rec_mutex_unlock (&self->priv->__lock__colour_enabled);
		if (_inner_error_ != NULL) {
			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_notify ((GObject *) self, "colour-enabled");
}


gboolean folks_debug_get_debug_output_enabled (FolksDebug* self) {
	gboolean result;
	GError * _inner_error_ = NULL;
	g_return_val_if_fail (self != NULL, FALSE);
	{
		g_static_rec_mutex_lock (&self->priv->__lock__debug_output_enabled);
		result = self->priv->_debug_output_enabled;
		g_static_rec_mutex_unlock (&self->priv->__lock__debug_output_enabled);
		return result;
		__finally20:
		g_static_rec_mutex_unlock (&self->priv->__lock__debug_output_enabled);
		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 FALSE;
	}
}


void folks_debug_set_debug_output_enabled (FolksDebug* self, gboolean value) {
	GError * _inner_error_ = NULL;
	g_return_if_fail (self != NULL);
	{
		g_static_rec_mutex_lock (&self->priv->__lock__debug_output_enabled);
		self->priv->_debug_output_enabled = value;
		__finally21:
		g_static_rec_mutex_unlock (&self->priv->__lock__debug_output_enabled);
		if (_inner_error_ != NULL) {
			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_notify ((GObject *) self, "debug-output-enabled");
}


static void folks_debug_key_value_pair_copy (const FolksDebugKeyValuePair* self, FolksDebugKeyValuePair* dest) {
	dest->key = g_strdup (self->key);
	dest->val = g_strdup (self->val);
}


static void folks_debug_key_value_pair_destroy (FolksDebugKeyValuePair* self) {
	_g_free0 ((*self).key);
	_g_free0 ((*self).val);
}


static FolksDebugKeyValuePair* folks_debug_key_value_pair_dup (const FolksDebugKeyValuePair* self) {
	FolksDebugKeyValuePair* dup;
	dup = g_new0 (FolksDebugKeyValuePair, 1);
	folks_debug_key_value_pair_copy (self, dup);
	return dup;
}


static void folks_debug_key_value_pair_free (FolksDebugKeyValuePair* self) {
	folks_debug_key_value_pair_destroy (self);
	g_free (self);
}


static GType folks_debug_key_value_pair_get_type (void) {
	static volatile gsize folks_debug_key_value_pair_type_id__volatile = 0;
	if (g_once_init_enter (&folks_debug_key_value_pair_type_id__volatile)) {
		GType folks_debug_key_value_pair_type_id;
		folks_debug_key_value_pair_type_id = g_boxed_type_register_static ("FolksDebugKeyValuePair", (GBoxedCopyFunc) folks_debug_key_value_pair_dup, (GBoxedFreeFunc) folks_debug_key_value_pair_free);
		g_once_init_leave (&folks_debug_key_value_pair_type_id__volatile, folks_debug_key_value_pair_type_id);
	}
	return folks_debug_key_value_pair_type_id__volatile;
}


static void folks_debug_class_init (FolksDebugClass * klass) {
	folks_debug_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (FolksDebugPrivate));
	G_OBJECT_CLASS (klass)->get_property = _vala_folks_debug_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_folks_debug_set_property;
	G_OBJECT_CLASS (klass)->finalize = folks_debug_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), FOLKS_DEBUG_COLOUR_ENABLED, g_param_spec_boolean ("colour-enabled", "colour-enabled", "colour-enabled", FALSE, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE));
	/**
	   * Whether debug output is enabled. This is orthogonal to the set of enabled
	   * debug domains; filtering of debug output as a whole is done after filtering
	   * by enabled domains.
	   *
	   * @since 0.5.1
	   */
	g_object_class_install_property (G_OBJECT_CLASS (klass), FOLKS_DEBUG_DEBUG_OUTPUT_ENABLED, g_param_spec_boolean ("debug-output-enabled", "debug-output-enabled", "debug-output-enabled", FALSE, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE));
	/**
	   * Signal emitted in the main thread whenever objects should print their
	   * current status. All significant objects in the library should connect
	   * to this and print their current status in some suitable format when it's
	   * emitted.
	   *
	   * Client processes should emit this signal by calling
	   * {@link Debug.emit_print_status}.
	   *
	   * @since 0.5.1
	   */
	g_signal_new ("print_status", FOLKS_TYPE_DEBUG, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
	g_static_rec_mutex_init (&__lock_folks_debug__instance);
}


static void folks_debug_instance_init (FolksDebug * self) {
	gchar* _tmp0_;
	self->priv = FOLKS_DEBUG_GET_PRIVATE (self);
	g_static_rec_mutex_init (&self->priv->__lock__domains);
	self->priv->_all = FALSE;
	self->priv->_indentation = (guint) 0;
	_tmp0_ = g_strdup ("");
	self->priv->_indentation_string = _tmp0_;
	g_static_rec_mutex_init (&self->priv->__lock__colour_enabled);
	self->priv->_colour_enabled = TRUE;
	g_static_rec_mutex_init (&self->priv->__lock__debug_output_enabled);
	self->priv->_debug_output_enabled = TRUE;
}


static void folks_debug_finalize (GObject* obj) {
	FolksDebug * self;
	GError * _inner_error_ = NULL;
	self = FOLKS_DEBUG (obj);
	{
		g_static_rec_mutex_lock (&__lock_folks_debug__instance);
		folks_debug__instance = NULL;
		__finally14:
		g_static_rec_mutex_unlock (&__lock_folks_debug__instance);
		if (_inner_error_ != NULL) {
			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_);
		}
	}
	g_static_rec_mutex_free (&self->priv->__lock__domains);
	_g_object_unref0 (self->priv->_domains);
	_g_free0 (self->priv->_indentation_string);
	g_static_rec_mutex_free (&self->priv->__lock__colour_enabled);
	g_static_rec_mutex_free (&self->priv->__lock__debug_output_enabled);
	G_OBJECT_CLASS (folks_debug_parent_class)->finalize (obj);
}


/**
 * Manage debug output and status reporting for all folks objects. All GLib
 * debug logging calls are passed through a log handler in this class, which
 * allows debug domains to be outputted according to whether they've been
 * enabled by being passed to {@link Debug.dup}.
 *
 * @since 0.5.1
 */
GType folks_debug_get_type (void) {
	static volatile gsize folks_debug_type_id__volatile = 0;
	if (g_once_init_enter (&folks_debug_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (FolksDebugClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) folks_debug_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (FolksDebug), 0, (GInstanceInitFunc) folks_debug_instance_init, NULL };
		GType folks_debug_type_id;
		folks_debug_type_id = g_type_register_static (G_TYPE_OBJECT, "FolksDebug", &g_define_type_info, 0);
		g_once_init_leave (&folks_debug_type_id__volatile, folks_debug_type_id);
	}
	return folks_debug_type_id__volatile;
}


static void _vala_folks_debug_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec) {
	FolksDebug * self;
	self = FOLKS_DEBUG (object);
	switch (property_id) {
		case FOLKS_DEBUG_COLOUR_ENABLED:
		g_value_set_boolean (value, folks_debug_get_colour_enabled (self));
		break;
		case FOLKS_DEBUG_DEBUG_OUTPUT_ENABLED:
		g_value_set_boolean (value, folks_debug_get_debug_output_enabled (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}


static void _vala_folks_debug_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec) {
	FolksDebug * self;
	self = FOLKS_DEBUG (object);
	switch (property_id) {
		case FOLKS_DEBUG_COLOUR_ENABLED:
		folks_debug_set_colour_enabled (self, g_value_get_boolean (value));
		break;
		case FOLKS_DEBUG_DEBUG_OUTPUT_ENABLED:
		folks_debug_set_debug_output_enabled (self, g_value_get_boolean (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}


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;
}



