/* generic-runner-factory.c generated by valac 0.56.18-dirty, the Vala compiler
 * generated from generic-runner-factory.vala, do not modify */

/* This file is part of GNOME Games. License: GPL-3.0+.*/

#include "gnome-games.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  {
	GAMES_GENERIC_RUNNER_FACTORY_0_PROPERTY,
	GAMES_GENERIC_RUNNER_FACTORY_NUM_PROPERTIES
};
static GParamSpec* games_generic_runner_factory_properties[GAMES_GENERIC_RUNNER_FACTORY_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

struct _GamesGenericRunnerFactoryPrivate {
	GamesPlatform** platforms;
	gint platforms_length1;
	gint _platforms_size_;
	GamesGenericRunnerFactoryCreateRunner callback;
	gpointer callback_target;
	GDestroyNotify callback_target_destroy_notify;
};

static gint GamesGenericRunnerFactory_private_offset;
static gpointer games_generic_runner_factory_parent_class = NULL;
static GamesRunnerFactoryIface * games_generic_runner_factory_games_runner_factory_parent_iface = NULL;

static void _vala_array_add21 (GamesPlatform** * array,
                        gint* length,
                        gint* size,
                        GamesPlatform* value);
static GamesPlatform** games_generic_runner_factory_real_get_platforms (GamesRunnerFactory* base,
                                                                 gint* result_length1);
static GamesPlatform** _vala_array_dup10 (GamesPlatform** self,
                                   gssize length);
static GamesRunner* games_generic_runner_factory_real_create_runner (GamesRunnerFactory* base,
                                                              GamesGame* game,
                                                              GError** error);
static void games_generic_runner_factory_finalize (GObject * obj);
static GType games_generic_runner_factory_get_type_once (void);
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);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
games_generic_runner_factory_get_instance_private (GamesGenericRunnerFactory* self)
{
	return G_STRUCT_MEMBER_P (self, GamesGenericRunnerFactory_private_offset);
}

GamesGenericRunnerFactory*
games_generic_runner_factory_construct (GType object_type,
                                        GamesGenericRunnerFactoryCreateRunner callback,
                                        gpointer callback_target,
                                        GDestroyNotify callback_target_destroy_notify)
{
	GamesGenericRunnerFactory * self = NULL;
	GamesGenericRunnerFactoryCreateRunner _tmp0_;
	gpointer _tmp0__target;
	GDestroyNotify _tmp0__target_destroy_notify;
	GamesPlatform** _tmp1_;
	self = (GamesGenericRunnerFactory*) g_object_new (object_type, NULL);
	_tmp0_ = callback;
	_tmp0__target = callback_target;
	_tmp0__target_destroy_notify = callback_target_destroy_notify;
	callback = NULL;
	callback_target = NULL;
	callback_target_destroy_notify = NULL;
	(self->priv->callback_target_destroy_notify == NULL) ? NULL : (self->priv->callback_target_destroy_notify (self->priv->callback_target), NULL);
	self->priv->callback = NULL;
	self->priv->callback_target = NULL;
	self->priv->callback_target_destroy_notify = NULL;
	self->priv->callback = _tmp0_;
	self->priv->callback_target = _tmp0__target;
	self->priv->callback_target_destroy_notify = _tmp0__target_destroy_notify;
	_tmp1_ = g_new0 (GamesPlatform*, 0 + 1);
	self->priv->platforms = (_vala_array_free (self->priv->platforms, self->priv->platforms_length1, (GDestroyNotify) g_object_unref), NULL);
	self->priv->platforms = _tmp1_;
	self->priv->platforms_length1 = 0;
	self->priv->_platforms_size_ = self->priv->platforms_length1;
	(callback_target_destroy_notify == NULL) ? NULL : (callback_target_destroy_notify (callback_target), NULL);
	callback = NULL;
	callback_target = NULL;
	callback_target_destroy_notify = NULL;
	return self;
}

GamesGenericRunnerFactory*
games_generic_runner_factory_new (GamesGenericRunnerFactoryCreateRunner callback,
                                  gpointer callback_target,
                                  GDestroyNotify callback_target_destroy_notify)
{
	return games_generic_runner_factory_construct (GAMES_TYPE_GENERIC_RUNNER_FACTORY, callback, callback_target, callback_target_destroy_notify);
}

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

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

void
games_generic_runner_factory_add_platform (GamesGenericRunnerFactory* self,
                                           GamesPlatform* platform)
{
	GamesPlatform* _tmp0_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (platform != NULL);
	_tmp0_ = _g_object_ref0 (platform);
	_vala_array_add21 (&self->priv->platforms, &self->priv->platforms_length1, &self->priv->_platforms_size_, _tmp0_);
}

static GamesPlatform**
_vala_array_dup10 (GamesPlatform** self,
                   gssize length)
{
	if (length >= 0) {
		GamesPlatform** result;
		gssize i;
		result = g_new0 (GamesPlatform*, length + 1);
		for (i = 0; i < length; i++) {
			GamesPlatform* _tmp0_;
			_tmp0_ = _g_object_ref0 (self[i]);
			result[i] = _tmp0_;
		}
		return result;
	}
	return NULL;
}

static GamesPlatform**
games_generic_runner_factory_real_get_platforms (GamesRunnerFactory* base,
                                                 gint* result_length1)
{
	GamesGenericRunnerFactory * self;
	GamesPlatform** _tmp0_;
	gint _tmp0__length1;
	GamesPlatform** _tmp1_;
	gint _tmp1__length1;
	GamesPlatform** _tmp2_;
	gint _tmp2__length1;
	GamesPlatform** result;
	self = (GamesGenericRunnerFactory*) base;
	_tmp0_ = self->priv->platforms;
	_tmp0__length1 = self->priv->platforms_length1;
	_tmp1_ = (_tmp0_ != NULL) ? _vala_array_dup10 (_tmp0_, _tmp0__length1) : _tmp0_;
	_tmp1__length1 = _tmp0__length1;
	_tmp2_ = _tmp1_;
	_tmp2__length1 = _tmp1__length1;
	if (result_length1) {
		*result_length1 = _tmp2__length1;
	}
	result = _tmp2_;
	return result;
}

static GamesRunner*
games_generic_runner_factory_real_create_runner (GamesRunnerFactory* base,
                                                 GamesGame* game,
                                                 GError** error)
{
	GamesGenericRunnerFactory * self;
	GamesRunner* _tmp0_ = NULL;
	GamesGenericRunnerFactoryCreateRunner _tmp1_;
	gpointer _tmp1__target;
	GamesRunner* _tmp2_;
	GamesRunner* _tmp3_;
	GError* _inner_error0_ = NULL;
	GamesRunner* result;
	self = (GamesGenericRunnerFactory*) base;
	g_return_val_if_fail (game != NULL, NULL);
	_tmp1_ = self->priv->callback;
	_tmp1__target = self->priv->callback_target;
	_tmp2_ = _tmp1_ (game, _tmp1__target, &_inner_error0_);
	_tmp0_ = _tmp2_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		return NULL;
	}
	_tmp3_ = _tmp0_;
	_tmp0_ = NULL;
	result = _tmp3_;
	_g_object_unref0 (_tmp0_);
	return result;
}

static void
games_generic_runner_factory_class_init (GamesGenericRunnerFactoryClass * klass,
                                         gpointer klass_data)
{
	games_generic_runner_factory_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &GamesGenericRunnerFactory_private_offset);
	G_OBJECT_CLASS (klass)->finalize = games_generic_runner_factory_finalize;
}

static void
games_generic_runner_factory_games_runner_factory_interface_init (GamesRunnerFactoryIface * iface,
                                                                  gpointer iface_data)
{
	games_generic_runner_factory_games_runner_factory_parent_iface = g_type_interface_peek_parent (iface);
	iface->get_platforms = (GamesPlatform** (*) (GamesRunnerFactory*, gint*)) games_generic_runner_factory_real_get_platforms;
	iface->create_runner = (GamesRunner* (*) (GamesRunnerFactory*, GamesGame*, GError**)) games_generic_runner_factory_real_create_runner;
}

static void
games_generic_runner_factory_instance_init (GamesGenericRunnerFactory * self,
                                            gpointer klass)
{
	self->priv = games_generic_runner_factory_get_instance_private (self);
}

static void
games_generic_runner_factory_finalize (GObject * obj)
{
	GamesGenericRunnerFactory * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GAMES_TYPE_GENERIC_RUNNER_FACTORY, GamesGenericRunnerFactory);
	self->priv->platforms = (_vala_array_free (self->priv->platforms, self->priv->platforms_length1, (GDestroyNotify) g_object_unref), NULL);
	(self->priv->callback_target_destroy_notify == NULL) ? NULL : (self->priv->callback_target_destroy_notify (self->priv->callback_target), NULL);
	self->priv->callback = NULL;
	self->priv->callback_target = NULL;
	self->priv->callback_target_destroy_notify = NULL;
	G_OBJECT_CLASS (games_generic_runner_factory_parent_class)->finalize (obj);
}

static GType
games_generic_runner_factory_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GamesGenericRunnerFactoryClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) games_generic_runner_factory_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GamesGenericRunnerFactory), 0, (GInstanceInitFunc) games_generic_runner_factory_instance_init, NULL };
	static const GInterfaceInfo games_runner_factory_info = { (GInterfaceInitFunc) games_generic_runner_factory_games_runner_factory_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	GType games_generic_runner_factory_type_id;
	games_generic_runner_factory_type_id = g_type_register_static (G_TYPE_OBJECT, "GamesGenericRunnerFactory", &g_define_type_info, 0);
	g_type_add_interface_static (games_generic_runner_factory_type_id, GAMES_TYPE_RUNNER_FACTORY, &games_runner_factory_info);
	GamesGenericRunnerFactory_private_offset = g_type_add_instance_private (games_generic_runner_factory_type_id, sizeof (GamesGenericRunnerFactoryPrivate));
	return games_generic_runner_factory_type_id;
}

GType
games_generic_runner_factory_get_type (void)
{
	static volatile gsize games_generic_runner_factory_type_id__once = 0;
	if (g_once_init_enter (&games_generic_runner_factory_type_id__once)) {
		GType games_generic_runner_factory_type_id;
		games_generic_runner_factory_type_id = games_generic_runner_factory_get_type_once ();
		g_once_init_leave (&games_generic_runner_factory_type_id__once, games_generic_runner_factory_type_id);
	}
	return games_generic_runner_factory_type_id__once;
}

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

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

