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

#include "libdino.h"
#include <glib-object.h>
#include <glib.h>
#include <gobject/gvaluecollector.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

typedef struct _Block47Data Block47Data;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef struct _Block48Data Block48Data;
typedef struct _DinoParamSpecWeakTimeout DinoParamSpecWeakTimeout;

struct _Block47Data {
	int _ref_count_;
	GType t_type;
	GBoxedCopyFunc t_dup_func;
	GDestroyNotify t_destroy_func;
	GWeakRef weak;
	DinoWeakTimeoutSourceFunc function;
};

struct _Block48Data {
	int _ref_count_;
	GType t_type;
	GBoxedCopyFunc t_dup_func;
	GDestroyNotify t_destroy_func;
	GWeakRef weak;
	DinoWeakTimeoutSourceOnceFunc function;
};

struct _DinoParamSpecWeakTimeout {
	GParamSpec parent_instance;
};

static gpointer dino_weak_timeout_parent_class = NULL;

static Block47Data* block47_data_ref (Block47Data* _data47_);
static void block47_data_unref (void * _userdata_);
static gboolean __lambda148_ (Block47Data* _data47_);
static gboolean ___lambda148__gsource_func (gpointer self);
static Block48Data* block48_data_ref (Block48Data* _data48_);
static void block48_data_unref (void * _userdata_);
static gboolean __lambda149_ (Block48Data* _data48_);
static gboolean ___lambda149__gsource_func (gpointer self);
static void dino_weak_timeout_finalize (DinoWeakTimeout * obj);
static GType dino_weak_timeout_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static Block47Data*
block47_data_ref (Block47Data* _data47_)
{
	g_atomic_int_inc (&_data47_->_ref_count_);
	return _data47_;
}

static void
block47_data_unref (void * _userdata_)
{
	Block47Data* _data47_;
	_data47_ = (Block47Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data47_->_ref_count_)) {
		GType t_type;
		GBoxedCopyFunc t_dup_func;
		GDestroyNotify t_destroy_func;
		t_type = _data47_->t_type;
		t_dup_func = _data47_->t_dup_func;
		t_destroy_func = _data47_->t_destroy_func;
		g_weak_ref_clear (&_data47_->weak);
		g_slice_free (Block47Data, _data47_);
	}
}

static gboolean
__lambda148_ (Block47Data* _data47_)
{
	GType t_type;
	GBoxedCopyFunc t_dup_func;
	GDestroyNotify t_destroy_func;
	GObject* strong = NULL;
	GObject* _tmp0_;
	GObject* _tmp1_;
	GObject* _tmp2_;
	gboolean result;
	t_type = _data47_->t_type;
	t_dup_func = _data47_->t_dup_func;
	t_destroy_func = _data47_->t_destroy_func;
	_tmp0_ = g_weak_ref_get (&_data47_->weak);
	strong = _tmp0_;
	_tmp1_ = strong;
	if (_tmp1_ == NULL) {
		result = FALSE;
		_g_object_unref0 (strong);
		return result;
	}
	_tmp2_ = strong;
	result = _data47_->function (_tmp2_);
	_g_object_unref0 (strong);
	return result;
}

static gboolean
___lambda148__gsource_func (gpointer self)
{
	gboolean result;
	result = __lambda148_ (self);
	return result;
}

guint
dino_weak_timeout_add (GType t_type,
                       GBoxedCopyFunc t_dup_func,
                       GDestroyNotify t_destroy_func,
                       guint interval,
                       gconstpointer object,
                       DinoWeakTimeoutSourceFunc function,
                       gint priority)
{
	Block47Data* _data47_;
	guint result;
	_data47_ = g_slice_new0 (Block47Data);
	_data47_->_ref_count_ = 1;
	_data47_->t_type = t_type;
	_data47_->t_dup_func = t_dup_func;
	_data47_->t_destroy_func = t_destroy_func;
	_data47_->function = function;
	g_weak_ref_init (&_data47_->weak, G_TYPE_CHECK_INSTANCE_CAST (object, G_TYPE_OBJECT, GObject));
	result = g_timeout_add_full (priority, interval, ___lambda148__gsource_func, block47_data_ref (_data47_), block47_data_unref);
	block47_data_unref (_data47_);
	_data47_ = NULL;
	return result;
}

static Block48Data*
block48_data_ref (Block48Data* _data48_)
{
	g_atomic_int_inc (&_data48_->_ref_count_);
	return _data48_;
}

static void
block48_data_unref (void * _userdata_)
{
	Block48Data* _data48_;
	_data48_ = (Block48Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data48_->_ref_count_)) {
		GType t_type;
		GBoxedCopyFunc t_dup_func;
		GDestroyNotify t_destroy_func;
		t_type = _data48_->t_type;
		t_dup_func = _data48_->t_dup_func;
		t_destroy_func = _data48_->t_destroy_func;
		g_weak_ref_clear (&_data48_->weak);
		g_slice_free (Block48Data, _data48_);
	}
}

static gboolean
__lambda149_ (Block48Data* _data48_)
{
	GType t_type;
	GBoxedCopyFunc t_dup_func;
	GDestroyNotify t_destroy_func;
	GObject* strong = NULL;
	GObject* _tmp0_;
	GObject* _tmp1_;
	GObject* _tmp2_;
	gboolean result;
	t_type = _data48_->t_type;
	t_dup_func = _data48_->t_dup_func;
	t_destroy_func = _data48_->t_destroy_func;
	_tmp0_ = g_weak_ref_get (&_data48_->weak);
	strong = _tmp0_;
	_tmp1_ = strong;
	if (_tmp1_ == NULL) {
		result = FALSE;
		_g_object_unref0 (strong);
		return result;
	}
	_tmp2_ = strong;
	_data48_->function (_tmp2_);
	result = FALSE;
	_g_object_unref0 (strong);
	return result;
}

static gboolean
___lambda149__gsource_func (gpointer self)
{
	gboolean result;
	result = __lambda149_ (self);
	return result;
}

guint
dino_weak_timeout_add_once (GType t_type,
                            GBoxedCopyFunc t_dup_func,
                            GDestroyNotify t_destroy_func,
                            guint interval,
                            gconstpointer object,
                            DinoWeakTimeoutSourceOnceFunc function,
                            gint priority)
{
	Block48Data* _data48_;
	guint result;
	_data48_ = g_slice_new0 (Block48Data);
	_data48_->_ref_count_ = 1;
	_data48_->t_type = t_type;
	_data48_->t_dup_func = t_dup_func;
	_data48_->t_destroy_func = t_destroy_func;
	_data48_->function = function;
	g_weak_ref_init (&_data48_->weak, G_TYPE_CHECK_INSTANCE_CAST (object, G_TYPE_OBJECT, GObject));
	result = g_timeout_add_full (priority, interval, ___lambda149__gsource_func, block48_data_ref (_data48_), block48_data_unref);
	block48_data_unref (_data48_);
	_data48_ = NULL;
	return result;
}

guint
dino_weak_timeout_add_seconds (GType t_type,
                               GBoxedCopyFunc t_dup_func,
                               GDestroyNotify t_destroy_func,
                               guint interval,
                               gconstpointer object,
                               DinoWeakTimeoutSourceFunc function,
                               gint priority)
{
	DinoWeakTimeoutSourceFunc _tmp0_;
	guint result;
	_tmp0_ = function;
	function = NULL;
	result = dino_weak_timeout_add (t_type, (GBoxedCopyFunc) t_dup_func, (GDestroyNotify) t_destroy_func, interval * 1000, object, _tmp0_, priority);
	return result;
}

guint
dino_weak_timeout_add_seconds_once (GType t_type,
                                    GBoxedCopyFunc t_dup_func,
                                    GDestroyNotify t_destroy_func,
                                    guint interval,
                                    gconstpointer object,
                                    DinoWeakTimeoutSourceOnceFunc function,
                                    gint priority)
{
	DinoWeakTimeoutSourceOnceFunc _tmp0_;
	guint result;
	_tmp0_ = function;
	function = NULL;
	result = dino_weak_timeout_add_once (t_type, (GBoxedCopyFunc) t_dup_func, (GDestroyNotify) t_destroy_func, interval * 1000, object, _tmp0_, priority);
	return result;
}

DinoWeakTimeout*
dino_weak_timeout_construct (GType object_type)
{
	DinoWeakTimeout* self = NULL;
	self = (DinoWeakTimeout*) g_type_create_instance (object_type);
	return self;
}

DinoWeakTimeout*
dino_weak_timeout_new (void)
{
	return dino_weak_timeout_construct (DINO_TYPE_WEAK_TIMEOUT);
}

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

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

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

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

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

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

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

void
dino_value_set_weak_timeout (GValue* value,
                             gpointer v_object)
{
	DinoWeakTimeout * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, DINO_TYPE_WEAK_TIMEOUT));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, DINO_TYPE_WEAK_TIMEOUT));
		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;
		dino_weak_timeout_ref (value->data[0].v_pointer);
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		dino_weak_timeout_unref (old);
	}
}

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

static void
dino_weak_timeout_class_init (DinoWeakTimeoutClass * klass,
                              gpointer klass_data)
{
	dino_weak_timeout_parent_class = g_type_class_peek_parent (klass);
	((DinoWeakTimeoutClass *) klass)->finalize = dino_weak_timeout_finalize;
}

static void
dino_weak_timeout_instance_init (DinoWeakTimeout * self,
                                 gpointer klass)
{
	self->ref_count = 1;
}

static void
dino_weak_timeout_finalize (DinoWeakTimeout * obj)
{
	DinoWeakTimeout * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, DINO_TYPE_WEAK_TIMEOUT, DinoWeakTimeout);
	g_signal_handlers_destroy (self);
}

static GType
dino_weak_timeout_get_type_once (void)
{
	static const GTypeValueTable g_define_type_value_table = { dino_value_weak_timeout_init, dino_value_weak_timeout_free_value, dino_value_weak_timeout_copy_value, dino_value_weak_timeout_peek_pointer, "p", dino_value_weak_timeout_collect_value, "p", dino_value_weak_timeout_lcopy_value };
	static const GTypeInfo g_define_type_info = { sizeof (DinoWeakTimeoutClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) dino_weak_timeout_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DinoWeakTimeout), 0, (GInstanceInitFunc) dino_weak_timeout_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 dino_weak_timeout_type_id;
	dino_weak_timeout_type_id = g_type_register_fundamental (g_type_fundamental_next (), "DinoWeakTimeout", &g_define_type_info, &g_define_type_fundamental_info, 0);
	return dino_weak_timeout_type_id;
}

GType
dino_weak_timeout_get_type (void)
{
	static volatile gsize dino_weak_timeout_type_id__once = 0;
	if (g_once_init_enter (&dino_weak_timeout_type_id__once)) {
		GType dino_weak_timeout_type_id;
		dino_weak_timeout_type_id = dino_weak_timeout_get_type_once ();
		g_once_init_leave (&dino_weak_timeout_type_id__once, dino_weak_timeout_type_id);
	}
	return dino_weak_timeout_type_id__once;
}

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

void
dino_weak_timeout_unref (gpointer instance)
{
	DinoWeakTimeout * self;
	self = instance;
	if (g_atomic_int_dec_and_test (&self->ref_count)) {
		DINO_WEAK_TIMEOUT_GET_CLASS (self)->finalize (self);
		g_type_free_instance ((GTypeInstance *) self);
	}
}

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

