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

/*
Copyright (C) 2014 2015 2019 Johan Mattsson

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 3 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.
*/

#include "birdfont.h"
#include <glib.h>
#include <glib-object.h>
#include <string.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

enum  {
	BIRD_FONT_TASK_0_PROPERTY,
	BIRD_FONT_TASK_NUM_PROPERTIES
};
static GParamSpec* bird_font_task_properties[BIRD_FONT_TASK_NUM_PROPERTIES];
#define _g_source_unref0(var) ((var == NULL) ? NULL : (var = (g_source_unref (var), NULL)))
enum  {
	BIRD_FONT_TASK_DONE_SIGNAL,
	BIRD_FONT_TASK_NUM_SIGNALS
};
static guint bird_font_task_signals[BIRD_FONT_TASK_NUM_SIGNALS] = {0};

struct _BirdFontTaskPrivate {
	BirdFontTaskRunnable task;
	gpointer task_target;
	GDestroyNotify task_target_destroy_notify;
	gboolean cancelled;
	GRecMutex __lock_cancelled;
	gboolean cancelable;
};

static gint BirdFontTask_private_offset;
static gpointer bird_font_task_parent_class = NULL;

static void bird_font_task_real_run (BirdFontTask* self);
static gboolean __lambda8_ (BirdFontTask* self);
static gboolean ___lambda8__gsource_func (gpointer self);
static void bird_font_task_finalize (GObject * obj);
static GType bird_font_task_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
bird_font_task_get_instance_private (BirdFontTask* self)
{
	return G_STRUCT_MEMBER_P (self, BirdFontTask_private_offset);
}

BirdFontTask*
bird_font_task_construct_empty (GType object_type)
{
	BirdFontTask * self = NULL;
	self = (BirdFontTask*) g_object_new (object_type, NULL);
	return self;
}

BirdFontTask*
bird_font_task_new_empty (void)
{
	return bird_font_task_construct_empty (BIRD_FONT_TYPE_TASK);
}

BirdFontTask*
bird_font_task_construct (GType object_type,
                          BirdFontTaskRunnable r,
                          gpointer r_target,
                          GDestroyNotify r_target_destroy_notify,
                          gboolean cancelable)
{
	BirdFontTask * self = NULL;
	self = (BirdFontTask*) g_object_new (object_type, NULL);
	if (r != NULL) {
		BirdFontTaskRunnable _tmp0_;
		gpointer _tmp0__target;
		GDestroyNotify _tmp0__target_destroy_notify;
		_tmp0_ = r;
		_tmp0__target = r_target;
		_tmp0__target_destroy_notify = r_target_destroy_notify;
		r = NULL;
		r_target = NULL;
		r_target_destroy_notify = NULL;
		(self->priv->task_target_destroy_notify == NULL) ? NULL : (self->priv->task_target_destroy_notify (self->priv->task_target), NULL);
		self->priv->task = NULL;
		self->priv->task_target = NULL;
		self->priv->task_target_destroy_notify = NULL;
		self->priv->task = (BirdFontTaskRunnable) _tmp0_;
		self->priv->task_target = _tmp0__target;
		self->priv->task_target_destroy_notify = _tmp0__target_destroy_notify;
	}
	self->priv->cancelable = cancelable;
	(r_target_destroy_notify == NULL) ? NULL : (r_target_destroy_notify (r_target), NULL);
	r = NULL;
	r_target = NULL;
	r_target_destroy_notify = NULL;
	return self;
}

BirdFontTask*
bird_font_task_new (BirdFontTaskRunnable r,
                    gpointer r_target,
                    GDestroyNotify r_target_destroy_notify,
                    gboolean cancelable)
{
	return bird_font_task_construct (BIRD_FONT_TYPE_TASK, r, r_target, r_target_destroy_notify, cancelable);
}

gboolean
bird_font_task_is_cancellable (BirdFontTask* self)
{
	gboolean c = FALSE;
	GError* _inner_error0_ = NULL;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	{
		g_rec_mutex_lock (&self->priv->__lock_cancelled);
		{
			c = self->priv->cancelable;
		}
		__finally0:
		{
			g_rec_mutex_unlock (&self->priv->__lock_cancelled);
		}
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			gboolean _tmp0_ = FALSE;
			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 _tmp0_;
		}
	}
	result = c;
	return result;
}

void
bird_font_task_cancel (BirdFontTask* self)
{
	GError* _inner_error0_ = NULL;
	g_return_if_fail (self != NULL);
	{
		g_rec_mutex_lock (&self->priv->__lock_cancelled);
		{
			if (G_UNLIKELY (!self->priv->cancelable)) {
				g_warning ("Task.vala:49: Task is not cancelable.");
			}
			self->priv->cancelled = TRUE;
		}
		__finally0:
		{
			g_rec_mutex_unlock (&self->priv->__lock_cancelled);
		}
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			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;
		}
	}
}

gboolean
bird_font_task_is_cancelled (BirdFontTask* self)
{
	gboolean c = FALSE;
	GError* _inner_error0_ = NULL;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	{
		g_rec_mutex_lock (&self->priv->__lock_cancelled);
		{
			c = self->priv->cancelled;
		}
		__finally0:
		{
			g_rec_mutex_unlock (&self->priv->__lock_cancelled);
		}
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			gboolean _tmp0_ = FALSE;
			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 _tmp0_;
		}
	}
	result = c;
	return result;
}

static gboolean
__lambda8_ (BirdFontTask* self)
{
	gboolean result;
	g_signal_emit (self, bird_font_task_signals[BIRD_FONT_TASK_DONE_SIGNAL], 0);
	result = FALSE;
	return result;
}

static gboolean
___lambda8__gsource_func (gpointer self)
{
	gboolean result;
	result = __lambda8_ ((BirdFontTask*) self);
	return result;
}

static void
bird_font_task_real_run (BirdFontTask* self)
{
	BirdFontTaskRunnable _tmp0_;
	gpointer _tmp0__target;
	GSource* idle = NULL;
	GSource* _tmp1_;
	_tmp0_ = self->priv->task;
	_tmp0__target = self->priv->task_target;
	_tmp0_ (_tmp0__target);
	_tmp1_ = g_idle_source_new ();
	idle = _tmp1_;
	g_source_set_callback (idle, ___lambda8__gsource_func, g_object_ref (self), g_object_unref);
	g_source_attach (idle, NULL);
	_g_source_unref0 (idle);
}

void
bird_font_task_run (BirdFontTask* self)
{
	BirdFontTaskClass* _klass_;
	g_return_if_fail (self != NULL);
	_klass_ = BIRD_FONT_TASK_GET_CLASS (self);
	if (_klass_->run) {
		_klass_->run (self);
	}
}

void*
bird_font_task_perform_task (BirdFontTask* self)
{
	void* result;
	g_return_val_if_fail (self != NULL, NULL);
	bird_font_task_run (self);
	result = NULL;
	return result;
}

static void
bird_font_task_class_init (BirdFontTaskClass * klass,
                           gpointer klass_data)
{
	bird_font_task_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &BirdFontTask_private_offset);
	((BirdFontTaskClass *) klass)->run = (void (*) (BirdFontTask*)) bird_font_task_real_run;
	G_OBJECT_CLASS (klass)->finalize = bird_font_task_finalize;
	bird_font_task_signals[BIRD_FONT_TASK_DONE_SIGNAL] = g_signal_new ("done", BIRD_FONT_TYPE_TASK, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
}

static void
bird_font_task_instance_init (BirdFontTask * self,
                              gpointer klass)
{
	self->priv = bird_font_task_get_instance_private (self);
	g_rec_mutex_init (&self->priv->__lock_cancelled);
	self->priv->cancelled = FALSE;
	self->priv->cancelable = FALSE;
}

static void
bird_font_task_finalize (GObject * obj)
{
	BirdFontTask * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, BIRD_FONT_TYPE_TASK, BirdFontTask);
	(self->priv->task_target_destroy_notify == NULL) ? NULL : (self->priv->task_target_destroy_notify (self->priv->task_target), NULL);
	self->priv->task = NULL;
	self->priv->task_target = NULL;
	self->priv->task_target_destroy_notify = NULL;
	g_rec_mutex_clear (&self->priv->__lock_cancelled);
	G_OBJECT_CLASS (bird_font_task_parent_class)->finalize (obj);
}

static GType
bird_font_task_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (BirdFontTaskClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) bird_font_task_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (BirdFontTask), 0, (GInstanceInitFunc) bird_font_task_instance_init, NULL };
	GType bird_font_task_type_id;
	bird_font_task_type_id = g_type_register_static (G_TYPE_OBJECT, "BirdFontTask", &g_define_type_info, 0);
	BirdFontTask_private_offset = g_type_add_instance_private (bird_font_task_type_id, sizeof (BirdFontTaskPrivate));
	return bird_font_task_type_id;
}

GType
bird_font_task_get_type (void)
{
	static volatile gsize bird_font_task_type_id__once = 0;
	if (g_once_init_enter (&bird_font_task_type_id__once)) {
		GType bird_font_task_type_id;
		bird_font_task_type_id = bird_font_task_get_type_once ();
		g_once_init_leave (&bird_font_task_type_id__once, bird_font_task_type_id);
	}
	return bird_font_task_type_id__once;
}

static inline gpointer
_vala_memdup2 (gconstpointer mem,
               gsize byte_size)
{
	gpointer new_mem;
	if (mem && byte_size != 0) {
		new_mem = g_malloc (byte_size);
		memcpy (new_mem, mem, byte_size);
	} else {
		new_mem = NULL;
	}
	return new_mem;
}

