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

/*
* Copyright (c) 2010 Michal Hruby <michal.mhr@gmail.com>
*               2017 elementary LLC.
*
* This program 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 2 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
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA
*
* Authored by: Michal Hruby <michal.mhr@gmail.com>
*/

#include "slingshot.h"
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <gio/gio.h>
#include <glib-object.h>
#include <gobject/gvaluecollector.h>

#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif

#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef struct _SynapseUtilsQueryExistsAsyncData SynapseUtilsQueryExistsAsyncData;
typedef struct _SynapseUtilsDelegateWrapper SynapseUtilsDelegateWrapper;
typedef enum  {
	SYNAPSE_UTILS_ASYNC_ONCE_OPERATION_STATE_NOT_STARTED,
	SYNAPSE_UTILS_ASYNC_ONCE_OPERATION_STATE_IN_PROGRESS,
	SYNAPSE_UTILS_ASYNC_ONCE_OPERATION_STATE_DONE
} SynapseUtilsAsyncOnceOperationState;

#define SYNAPSE_UTILS_ASYNC_ONCE_TYPE_OPERATION_STATE (synapse_utils_async_once_operation_state_get_type ())
#define _synapse_utils_async_once_unref0(var) ((var == NULL) ? NULL : (var = (synapse_utils_async_once_unref (var), NULL)))
typedef struct _SynapseUtilsAsyncOnceEnterData SynapseUtilsAsyncOnceEnterData;
typedef struct _SynapseUtilsAsyncOnceWaitAsyncData SynapseUtilsAsyncOnceWaitAsyncData;
typedef struct _SynapseUtilsParamSpecAsyncOnce SynapseUtilsParamSpecAsyncOnce;

struct _SynapseUtilsQueryExistsAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GFile* f;
	gboolean result;
	gboolean exists;
	GFileInfo* _tmp0_;
	GFileInfo* _tmp1_;
	GError* _inner_error0_;
};

struct _SynapseUtilsDelegateWrapper {
	GSourceFunc callback;
	gpointer callback_target;
	GDestroyNotify callback_target_destroy_notify;
};

struct _SynapseUtilsAsyncOncePrivate {
	GType g_type;
	GBoxedCopyFunc g_dup_func;
	GDestroyNotify g_destroy_func;
	gpointer inner;
	SynapseUtilsAsyncOnceOperationState state;
	SynapseUtilsDelegateWrapper** callbacks;
	gint callbacks_length1;
	gint _callbacks_size_;
};

struct _SynapseUtilsAsyncOnceEnterData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	SynapseUtilsAsyncOnce* self;
	gboolean result;
};

struct _SynapseUtilsAsyncOnceWaitAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	SynapseUtilsAsyncOnce* self;
	SynapseUtilsDelegateWrapper* _tmp0_;
};

struct _SynapseUtilsParamSpecAsyncOnce {
	GParamSpec parent_instance;
};

static gint SynapseUtilsAsyncOnce_private_offset;
static gpointer synapse_utils_async_once_parent_class = NULL;
static GType synapse_utils_async_once_type_id = 0;

static void synapse_utils_query_exists_async_data_free (gpointer _data);
static gboolean synapse_utils_query_exists_async_co (SynapseUtilsQueryExistsAsyncData* _data_);
static void synapse_utils_query_exists_async_ready (GObject* source_object,
                                             GAsyncResult* _res_,
                                             gpointer _user_data_);
VALA_EXTERN void synapse_utils_delegate_wrapper_free (SynapseUtilsDelegateWrapper * self);
static void synapse_utils_delegate_wrapper_instance_init (SynapseUtilsDelegateWrapper * self);
VALA_EXTERN SynapseUtilsDelegateWrapper* synapse_utils_delegate_wrapper_new (GSourceFunc cb,
                                                                 gpointer cb_target,
                                                                 GDestroyNotify cb_target_destroy_notify);
static GType synapse_utils_async_once_operation_state_get_type (void) G_GNUC_CONST  G_GNUC_UNUSED ;
static void synapse_utils_async_once_enter_data_free (gpointer _data);
static gboolean synapse_utils_async_once_enter_co (SynapseUtilsAsyncOnceEnterData* _data_);
static void synapse_utils_async_once_wait_async (SynapseUtilsAsyncOnce* self,
                                          GAsyncReadyCallback _callback_,
                                          gpointer _user_data_);
static void synapse_utils_async_once_wait_finish (SynapseUtilsAsyncOnce* self,
                                           GAsyncResult* _res_);
static void synapse_utils_async_once_enter_ready (GObject* source_object,
                                           GAsyncResult* _res_,
                                           gpointer _user_data_);
static void synapse_utils_async_once_notify_all (SynapseUtilsAsyncOnce* self);
static void synapse_utils_async_once_wait_async_data_free (gpointer _data);
static gboolean synapse_utils_async_once_wait_async_co (SynapseUtilsAsyncOnceWaitAsyncData* _data_);
static gboolean _synapse_utils_async_once_wait_async_co_gsource_func (gpointer self);
static void _vala_array_add32 (SynapseUtilsDelegateWrapper** * array,
                        gint* length,
                        gint* size,
                        SynapseUtilsDelegateWrapper* value);
static void synapse_utils_async_once_finalize (SynapseUtilsAsyncOnce * obj);
static void _vala_array_destroy (gpointer array,
                          gssize array_length,
                          GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array,
                       gssize array_length,
                       GDestroyNotify destroy_func);

gchar*
synapse_utils_remove_accents (const gchar* input)
{
	gchar* _result_ = NULL;
	const gchar* charset = NULL;
	const gchar* _tmp0_ = NULL;
	GError* _inner_error0_ = NULL;
	gchar* result;
	g_return_val_if_fail (input != NULL, NULL);
	g_get_charset (&_tmp0_);
	charset = _tmp0_;
	{
		gchar* _tmp1_ = NULL;
		gint _tmp2_;
		gint _tmp3_;
		const gchar* _tmp4_;
		gchar* _tmp5_;
		gchar* _tmp6_;
		const gchar* _tmp7_;
		_tmp2_ = strlen (input);
		_tmp3_ = _tmp2_;
		_tmp4_ = charset;
		_tmp5_ = g_convert (input, (gssize) _tmp3_, "US-ASCII//TRANSLIT", _tmp4_, NULL, NULL, &_inner_error0_);
		_tmp1_ = _tmp5_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			if (_inner_error0_->domain == G_CONVERT_ERROR) {
				goto __catch0_g_convert_error;
			}
			_g_free0 (_result_);
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return NULL;
		}
		_tmp6_ = _tmp1_;
		_tmp1_ = NULL;
		_g_free0 (_result_);
		_result_ = _tmp6_;
		_tmp7_ = _result_;
		if (g_strcmp0 (input, _tmp7_) == 0) {
			result = NULL;
			_g_free0 (_tmp1_);
			_g_free0 (_result_);
			return result;
		}
		_g_free0 (_tmp1_);
	}
	goto __finally0;
	__catch0_g_convert_error:
	{
		g_clear_error (&_inner_error0_);
		_g_free0 (_result_);
		_result_ = NULL;
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		_g_free0 (_result_);
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
		g_clear_error (&_inner_error0_);
		return NULL;
	}
	result = _result_;
	return result;
}

static void
synapse_utils_query_exists_async_data_free (gpointer _data)
{
	SynapseUtilsQueryExistsAsyncData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->f);
	g_slice_free (SynapseUtilsQueryExistsAsyncData, _data_);
}

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

void
synapse_utils_query_exists_async (GFile* f,
                                  GAsyncReadyCallback _callback_,
                                  gpointer _user_data_)
{
	SynapseUtilsQueryExistsAsyncData* _data_;
	GFile* _tmp0_;
	g_return_if_fail (f != NULL);
	_data_ = g_slice_new0 (SynapseUtilsQueryExistsAsyncData);
	_data_->_async_result = g_task_new (NULL, NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, synapse_utils_query_exists_async_data_free);
	_tmp0_ = _g_object_ref0 (f);
	_g_object_unref0 (_data_->f);
	_data_->f = _tmp0_;
	synapse_utils_query_exists_async_co (_data_);
}

gboolean
synapse_utils_query_exists_finish (GAsyncResult* _res_)
{
	gboolean result;
	SynapseUtilsQueryExistsAsyncData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
	result = _data_->result;
	return result;
}

static void
synapse_utils_query_exists_async_ready (GObject* source_object,
                                        GAsyncResult* _res_,
                                        gpointer _user_data_)
{
	SynapseUtilsQueryExistsAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	synapse_utils_query_exists_async_co (_data_);
}

static gboolean
synapse_utils_query_exists_async_co (SynapseUtilsQueryExistsAsyncData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	{
		_data_->_state_ = 1;
		g_file_query_info_async (_data_->f, G_FILE_ATTRIBUTE_STANDARD_TYPE, 0, 0, NULL, synapse_utils_query_exists_async_ready, _data_);
		return FALSE;
		_state_1:
		_data_->_tmp0_ = g_file_query_info_finish (_data_->f, _data_->_res_, &_data_->_inner_error0_);
		_data_->_tmp1_ = _data_->_tmp0_;
		_g_object_unref0 (_data_->_tmp1_);
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_data_->exists = TRUE;
	}
	goto __finally0;
	__catch0_g_error:
	{
		g_clear_error (&_data_->_inner_error0_);
		_data_->exists = FALSE;
	}
	__finally0:
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
		g_clear_error (&_data_->_inner_error0_);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->result = _data_->exists;
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

SynapseUtilsDelegateWrapper*
synapse_utils_delegate_wrapper_new (GSourceFunc cb,
                                    gpointer cb_target,
                                    GDestroyNotify cb_target_destroy_notify)
{
	SynapseUtilsDelegateWrapper* self;
	GSourceFunc _tmp0_;
	gpointer _tmp0__target;
	GDestroyNotify _tmp0__target_destroy_notify;
	self = g_slice_new0 (SynapseUtilsDelegateWrapper);
	synapse_utils_delegate_wrapper_instance_init (self);
	_tmp0_ = cb;
	_tmp0__target = cb_target;
	_tmp0__target_destroy_notify = cb_target_destroy_notify;
	cb = NULL;
	cb_target = NULL;
	cb_target_destroy_notify = NULL;
	(self->callback_target_destroy_notify == NULL) ? NULL : (self->callback_target_destroy_notify (self->callback_target), NULL);
	self->callback = NULL;
	self->callback_target = NULL;
	self->callback_target_destroy_notify = NULL;
	self->callback = _tmp0_;
	self->callback_target = _tmp0__target;
	self->callback_target_destroy_notify = _tmp0__target_destroy_notify;
	(cb_target_destroy_notify == NULL) ? NULL : (cb_target_destroy_notify (cb_target), NULL);
	cb = NULL;
	cb_target = NULL;
	cb_target_destroy_notify = NULL;
	return self;
}

static void
synapse_utils_delegate_wrapper_instance_init (SynapseUtilsDelegateWrapper * self)
{
}

void
synapse_utils_delegate_wrapper_free (SynapseUtilsDelegateWrapper * self)
{
	(self->callback_target_destroy_notify == NULL) ? NULL : (self->callback_target_destroy_notify (self->callback_target), NULL);
	self->callback = NULL;
	self->callback_target = NULL;
	self->callback_target_destroy_notify = NULL;
	g_slice_free (SynapseUtilsDelegateWrapper, self);
}

static inline gpointer
synapse_utils_async_once_get_instance_private (SynapseUtilsAsyncOnce* self)
{
	return G_STRUCT_MEMBER_P (self, SynapseUtilsAsyncOnce_private_offset);
}

static GType
synapse_utils_async_once_operation_state_get_type_once (void)
{
	static const GEnumValue values[] = {{SYNAPSE_UTILS_ASYNC_ONCE_OPERATION_STATE_NOT_STARTED, "SYNAPSE_UTILS_ASYNC_ONCE_OPERATION_STATE_NOT_STARTED", "not-started"}, {SYNAPSE_UTILS_ASYNC_ONCE_OPERATION_STATE_IN_PROGRESS, "SYNAPSE_UTILS_ASYNC_ONCE_OPERATION_STATE_IN_PROGRESS", "in-progress"}, {SYNAPSE_UTILS_ASYNC_ONCE_OPERATION_STATE_DONE, "SYNAPSE_UTILS_ASYNC_ONCE_OPERATION_STATE_DONE", "done"}, {0, NULL, NULL}};
	GType synapse_utils_async_once_operation_state_type_id;
	synapse_utils_async_once_operation_state_type_id = g_enum_register_static ("SynapseUtilsAsyncOnceOperationState", values);
	return synapse_utils_async_once_operation_state_type_id;
}

static GType
synapse_utils_async_once_operation_state_get_type (void)
{
	static volatile gsize synapse_utils_async_once_operation_state_type_id__once = 0;
	if (g_once_init_enter (&synapse_utils_async_once_operation_state_type_id__once)) {
		GType synapse_utils_async_once_operation_state_type_id;
		synapse_utils_async_once_operation_state_type_id = synapse_utils_async_once_operation_state_get_type_once ();
		g_once_init_leave (&synapse_utils_async_once_operation_state_type_id__once, synapse_utils_async_once_operation_state_type_id);
	}
	return synapse_utils_async_once_operation_state_type_id__once;
}

SynapseUtilsAsyncOnce*
synapse_utils_async_once_construct (GType object_type,
                                    GType g_type,
                                    GBoxedCopyFunc g_dup_func,
                                    GDestroyNotify g_destroy_func)
{
	SynapseUtilsAsyncOnce* self = NULL;
	self = (SynapseUtilsAsyncOnce*) g_type_create_instance (object_type);
	self->priv->g_type = g_type;
	self->priv->g_dup_func = g_dup_func;
	self->priv->g_destroy_func = g_destroy_func;
	self->priv->state = SYNAPSE_UTILS_ASYNC_ONCE_OPERATION_STATE_NOT_STARTED;
	return self;
}

SynapseUtilsAsyncOnce*
synapse_utils_async_once_new (GType g_type,
                              GBoxedCopyFunc g_dup_func,
                              GDestroyNotify g_destroy_func)
{
	return synapse_utils_async_once_construct (SYNAPSE_UTILS_TYPE_ASYNC_ONCE, g_type, g_dup_func, g_destroy_func);
}

gboolean
synapse_utils_async_once_is_initialized (SynapseUtilsAsyncOnce* self)
{
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	result = self->priv->state == SYNAPSE_UTILS_ASYNC_ONCE_OPERATION_STATE_DONE;
	return result;
}

static void
synapse_utils_async_once_enter_data_free (gpointer _data)
{
	SynapseUtilsAsyncOnceEnterData* _data_;
	_data_ = _data;
	_synapse_utils_async_once_unref0 (_data_->self);
	g_slice_free (SynapseUtilsAsyncOnceEnterData, _data_);
}

static gpointer
_synapse_utils_async_once_ref0 (gpointer self)
{
	return self ? synapse_utils_async_once_ref (self) : NULL;
}

void
synapse_utils_async_once_enter (SynapseUtilsAsyncOnce* self,
                                GAsyncReadyCallback _callback_,
                                gpointer _user_data_)
{
	SynapseUtilsAsyncOnceEnterData* _data_;
	SynapseUtilsAsyncOnce* _tmp0_;
	g_return_if_fail (self != NULL);
	_data_ = g_slice_new0 (SynapseUtilsAsyncOnceEnterData);
	_data_->_async_result = g_task_new (NULL, NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, synapse_utils_async_once_enter_data_free);
	_tmp0_ = _synapse_utils_async_once_ref0 (self);
	_data_->self = _tmp0_;
	synapse_utils_async_once_enter_co (_data_);
}

gboolean
synapse_utils_async_once_enter_finish (SynapseUtilsAsyncOnce* self,
                                       GAsyncResult* _res_)
{
	gboolean result;
	SynapseUtilsAsyncOnceEnterData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
	result = _data_->result;
	return result;
}

static void
synapse_utils_async_once_enter_ready (GObject* source_object,
                                      GAsyncResult* _res_,
                                      gpointer _user_data_)
{
	SynapseUtilsAsyncOnceEnterData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	synapse_utils_async_once_enter_co (_data_);
}

static gboolean
synapse_utils_async_once_enter_co (SynapseUtilsAsyncOnceEnterData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	if (_data_->self->priv->state == SYNAPSE_UTILS_ASYNC_ONCE_OPERATION_STATE_NOT_STARTED) {
		_data_->self->priv->state = SYNAPSE_UTILS_ASYNC_ONCE_OPERATION_STATE_IN_PROGRESS;
		_data_->result = TRUE;
		g_task_return_pointer (_data_->_async_result, _data_, NULL);
		if (_data_->_state_ != 0) {
			while (!g_task_get_completed (_data_->_async_result)) {
				g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
			}
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	} else {
		if (_data_->self->priv->state == SYNAPSE_UTILS_ASYNC_ONCE_OPERATION_STATE_IN_PROGRESS) {
			_data_->_state_ = 1;
			synapse_utils_async_once_wait_async (_data_->self, synapse_utils_async_once_enter_ready, _data_);
			return FALSE;
			_state_1:
			synapse_utils_async_once_wait_finish (_data_->self, _data_->_res_);
		}
	}
	_data_->result = FALSE;
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

void
synapse_utils_async_once_leave (SynapseUtilsAsyncOnce* self,
                                gconstpointer _result_)
{
	gpointer _tmp0_;
	g_return_if_fail (self != NULL);
	if (self->priv->state != SYNAPSE_UTILS_ASYNC_ONCE_OPERATION_STATE_IN_PROGRESS) {
		g_warning ("utils.vala:126: Incorrect usage of AsyncOnce");
		return;
	}
	self->priv->state = SYNAPSE_UTILS_ASYNC_ONCE_OPERATION_STATE_DONE;
	_tmp0_ = ((_result_ != NULL) && (self->priv->g_dup_func != NULL)) ? self->priv->g_dup_func ((gpointer) _result_) : ((gpointer) _result_);
	((self->priv->inner == NULL) || (self->priv->g_destroy_func == NULL)) ? NULL : (self->priv->inner = (self->priv->g_destroy_func (self->priv->inner), NULL));
	self->priv->inner = _tmp0_;
	synapse_utils_async_once_notify_all (self);
}

static void
synapse_utils_async_once_notify_all (SynapseUtilsAsyncOnce* self)
{
	SynapseUtilsDelegateWrapper** _tmp0_;
	gint _tmp0__length1;
	SynapseUtilsDelegateWrapper** _tmp3_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->callbacks;
	_tmp0__length1 = self->priv->callbacks_length1;
	{
		SynapseUtilsDelegateWrapper** wrapper_collection = NULL;
		gint wrapper_collection_length1 = 0;
		gint _wrapper_collection_size_ = 0;
		gint wrapper_it = 0;
		wrapper_collection = _tmp0_;
		wrapper_collection_length1 = _tmp0__length1;
		for (wrapper_it = 0; wrapper_it < wrapper_collection_length1; wrapper_it = wrapper_it + 1) {
			SynapseUtilsDelegateWrapper* wrapper = NULL;
			wrapper = wrapper_collection[wrapper_it];
			{
				SynapseUtilsDelegateWrapper* _tmp1_;
				GSourceFunc _tmp2_;
				gpointer _tmp2__target;
				_tmp1_ = wrapper;
				_tmp2_ = _tmp1_->callback;
				_tmp2__target = _tmp1_->callback_target;
				_tmp2_ (_tmp2__target);
			}
		}
	}
	_tmp3_ = g_new0 (SynapseUtilsDelegateWrapper*, 0 + 1);
	self->priv->callbacks = (_vala_array_free (self->priv->callbacks, self->priv->callbacks_length1, (GDestroyNotify) synapse_utils_delegate_wrapper_free), NULL);
	self->priv->callbacks = _tmp3_;
	self->priv->callbacks_length1 = 0;
	self->priv->_callbacks_size_ = self->priv->callbacks_length1;
}

static void
synapse_utils_async_once_wait_async_data_free (gpointer _data)
{
	SynapseUtilsAsyncOnceWaitAsyncData* _data_;
	_data_ = _data;
	_synapse_utils_async_once_unref0 (_data_->self);
	g_slice_free (SynapseUtilsAsyncOnceWaitAsyncData, _data_);
}

static void
synapse_utils_async_once_wait_async (SynapseUtilsAsyncOnce* self,
                                     GAsyncReadyCallback _callback_,
                                     gpointer _user_data_)
{
	SynapseUtilsAsyncOnceWaitAsyncData* _data_;
	SynapseUtilsAsyncOnce* _tmp0_;
	g_return_if_fail (self != NULL);
	_data_ = g_slice_new0 (SynapseUtilsAsyncOnceWaitAsyncData);
	_data_->_async_result = g_task_new (NULL, NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, synapse_utils_async_once_wait_async_data_free);
	_tmp0_ = _synapse_utils_async_once_ref0 (self);
	_data_->self = _tmp0_;
	synapse_utils_async_once_wait_async_co (_data_);
}

static void
synapse_utils_async_once_wait_finish (SynapseUtilsAsyncOnce* self,
                                      GAsyncResult* _res_)
{
	SynapseUtilsAsyncOnceWaitAsyncData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
}

static gboolean
_synapse_utils_async_once_wait_async_co_gsource_func (gpointer self)
{
	gboolean result;
	result = synapse_utils_async_once_wait_async_co (self);
	return result;
}

static void
_vala_array_add32 (SynapseUtilsDelegateWrapper** * array,
                   gint* length,
                   gint* size,
                   SynapseUtilsDelegateWrapper* value)
{
	if ((*length) == (*size)) {
		*size = (*size) ? (2 * (*size)) : 4;
		*array = g_renew (SynapseUtilsDelegateWrapper*, *array, (*size) + 1);
	}
	(*array)[(*length)++] = value;
	(*array)[*length] = NULL;
}

static gboolean
synapse_utils_async_once_wait_async_co (SynapseUtilsAsyncOnceWaitAsyncData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = synapse_utils_delegate_wrapper_new (_synapse_utils_async_once_wait_async_co_gsource_func, _data_, NULL);
	_vala_array_add32 (&_data_->self->priv->callbacks, &_data_->self->priv->callbacks_length1, &_data_->self->priv->_callbacks_size_, _data_->_tmp0_);
	_data_->_state_ = 1;
	return FALSE;
	_state_1:
	;
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

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

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

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

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

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

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

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

void
synapse_utils_value_set_async_once (GValue* value,
                                    gpointer v_object)
{
	SynapseUtilsAsyncOnce * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, SYNAPSE_UTILS_TYPE_ASYNC_ONCE));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, SYNAPSE_UTILS_TYPE_ASYNC_ONCE));
		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;
		synapse_utils_async_once_ref (value->data[0].v_pointer);
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		synapse_utils_async_once_unref (old);
	}
}

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

static void
synapse_utils_async_once_class_init (SynapseUtilsAsyncOnceClass * klass,
                                     gpointer klass_data)
{
	synapse_utils_async_once_parent_class = g_type_class_peek_parent (klass);
	((SynapseUtilsAsyncOnceClass *) klass)->finalize = synapse_utils_async_once_finalize;
	g_type_class_adjust_private_offset (klass, &SynapseUtilsAsyncOnce_private_offset);
}

static void
synapse_utils_async_once_instance_init (SynapseUtilsAsyncOnce * self,
                                        gpointer klass)
{
	SynapseUtilsDelegateWrapper** _tmp0_;
	self->priv = synapse_utils_async_once_get_instance_private (self);
	_tmp0_ = g_new0 (SynapseUtilsDelegateWrapper*, 0 + 1);
	self->priv->callbacks = _tmp0_;
	self->priv->callbacks_length1 = 0;
	self->priv->_callbacks_size_ = self->priv->callbacks_length1;
	self->ref_count = 1;
}

static void
synapse_utils_async_once_finalize (SynapseUtilsAsyncOnce * obj)
{
	SynapseUtilsAsyncOnce * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, SYNAPSE_UTILS_TYPE_ASYNC_ONCE, SynapseUtilsAsyncOnce);
	g_signal_handlers_destroy (self);
	((self->priv->inner == NULL) || (self->priv->g_destroy_func == NULL)) ? NULL : (self->priv->inner = (self->priv->g_destroy_func (self->priv->inner), NULL));
	self->priv->callbacks = (_vala_array_free (self->priv->callbacks, self->priv->callbacks_length1, (GDestroyNotify) synapse_utils_delegate_wrapper_free), NULL);
}

GType
synapse_utils_async_once_get_type (void)
{
	return synapse_utils_async_once_type_id;
}

GType
synapse_utils_async_once_register_type (GTypeModule * module)
{
	static const GTypeValueTable g_define_type_value_table = { synapse_utils_value_async_once_init, synapse_utils_value_async_once_free_value, synapse_utils_value_async_once_copy_value, synapse_utils_value_async_once_peek_pointer, "p", synapse_utils_value_async_once_collect_value, "p", synapse_utils_value_async_once_lcopy_value };
	static const GTypeInfo g_define_type_info = { sizeof (SynapseUtilsAsyncOnceClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) synapse_utils_async_once_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (SynapseUtilsAsyncOnce), 0, (GInstanceInitFunc) synapse_utils_async_once_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) };
	synapse_utils_async_once_type_id = g_type_register_fundamental (g_type_fundamental_next (), "SynapseUtilsAsyncOnce", &g_define_type_info, &g_define_type_fundamental_info, 0);
	SynapseUtilsAsyncOnce_private_offset = sizeof (SynapseUtilsAsyncOncePrivate);
	return synapse_utils_async_once_type_id;
}

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

void
synapse_utils_async_once_unref (gpointer instance)
{
	SynapseUtilsAsyncOnce * self;
	self = instance;
	if (g_atomic_int_dec_and_test (&self->ref_count)) {
		SYNAPSE_UTILS_ASYNC_ONCE_GET_CLASS (self)->finalize (self);
		g_type_free_instance ((GTypeInstance *) self);
	}
}

static void
_vala_array_destroy (gpointer array,
                     gssize array_length,
                     GDestroyNotify destroy_func)
{
	if ((array != NULL) && (destroy_func != NULL)) {
		gssize 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,
                  gssize array_length,
                  GDestroyNotify destroy_func)
{
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}

