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

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

#include "gnome-games.h"
#include <glib-object.h>
#include <glib.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_RETRO_RUNNER_FACTORY_0_PROPERTY,
	GAMES_RETRO_RUNNER_FACTORY_NUM_PROPERTIES
};
static GParamSpec* games_retro_runner_factory_properties[GAMES_RETRO_RUNNER_FACTORY_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

struct _GamesRetroRunnerFactoryPrivate {
	GamesRetroPlatform* platform;
};

static gint GamesRetroRunnerFactory_private_offset;
static gpointer games_retro_runner_factory_parent_class = NULL;
static GamesRunnerFactoryIface * games_retro_runner_factory_games_runner_factory_parent_iface = NULL;

static GamesPlatform** games_retro_runner_factory_real_get_platforms (GamesRunnerFactory* base,
                                                               gint* result_length1);
static GamesRunner* games_retro_runner_factory_real_create_runner (GamesRunnerFactory* base,
                                                            GamesGame* game,
                                                            GError** error);
static void games_retro_runner_factory_finalize (GObject * obj);
static GType games_retro_runner_factory_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
games_retro_runner_factory_get_instance_private (GamesRetroRunnerFactory* self)
{
	return G_STRUCT_MEMBER_P (self, GamesRetroRunnerFactory_private_offset);
}

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

GamesRetroRunnerFactory*
games_retro_runner_factory_construct (GType object_type,
                                      GamesRetroPlatform* platform)
{
	GamesRetroRunnerFactory * self = NULL;
	GamesRetroPlatform* _tmp0_;
	g_return_val_if_fail (platform != NULL, NULL);
	self = (GamesRetroRunnerFactory*) g_object_new (object_type, NULL);
	_tmp0_ = _g_object_ref0 (platform);
	_g_object_unref0 (self->priv->platform);
	self->priv->platform = _tmp0_;
	return self;
}

GamesRetroRunnerFactory*
games_retro_runner_factory_new (GamesRetroPlatform* platform)
{
	return games_retro_runner_factory_construct (GAMES_TYPE_RETRO_RUNNER_FACTORY, platform);
}

static GamesPlatform**
games_retro_runner_factory_real_get_platforms (GamesRunnerFactory* base,
                                               gint* result_length1)
{
	GamesRetroRunnerFactory * self;
	GamesRetroPlatform* _tmp0_;
	GamesPlatform* _tmp1_;
	GamesPlatform** _tmp2_;
	GamesPlatform** _tmp3_;
	gint _tmp3__length1;
	GamesPlatform** result;
	self = (GamesRetroRunnerFactory*) base;
	_tmp0_ = self->priv->platform;
	_tmp1_ = _g_object_ref0 ((GamesPlatform*) _tmp0_);
	_tmp2_ = g_new0 (GamesPlatform*, 1 + 1);
	_tmp2_[0] = _tmp1_;
	_tmp3_ = _tmp2_;
	_tmp3__length1 = 1;
	if (result_length1) {
		*result_length1 = _tmp3__length1;
	}
	result = _tmp3_;
	return result;
}

static GamesRunner*
games_retro_runner_factory_real_create_runner (GamesRunnerFactory* base,
                                               GamesGame* game,
                                               GError** error)
{
	GamesRetroRunnerFactory * self;
	GamesRetroCoreSource* core_source = NULL;
	GamesRetroPlatform* _tmp0_;
	GamesRetroCoreSource* _tmp1_;
	GamesRetroRunner* _tmp2_;
	GamesRunner* result;
	self = (GamesRetroRunnerFactory*) base;
	g_return_val_if_fail (game != NULL, NULL);
	_tmp0_ = self->priv->platform;
	_tmp1_ = games_retro_core_source_new (_tmp0_);
	core_source = _tmp1_;
	_tmp2_ = games_retro_runner_new_from_source (game, core_source);
	result = (GamesRunner*) _tmp2_;
	_g_object_unref0 (core_source);
	return result;
}

static void
games_retro_runner_factory_class_init (GamesRetroRunnerFactoryClass * klass,
                                       gpointer klass_data)
{
	games_retro_runner_factory_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &GamesRetroRunnerFactory_private_offset);
	G_OBJECT_CLASS (klass)->finalize = games_retro_runner_factory_finalize;
}

static void
games_retro_runner_factory_games_runner_factory_interface_init (GamesRunnerFactoryIface * iface,
                                                                gpointer iface_data)
{
	games_retro_runner_factory_games_runner_factory_parent_iface = g_type_interface_peek_parent (iface);
	iface->get_platforms = (GamesPlatform** (*) (GamesRunnerFactory*, gint*)) games_retro_runner_factory_real_get_platforms;
	iface->create_runner = (GamesRunner* (*) (GamesRunnerFactory*, GamesGame*, GError**)) games_retro_runner_factory_real_create_runner;
}

static void
games_retro_runner_factory_instance_init (GamesRetroRunnerFactory * self,
                                          gpointer klass)
{
	self->priv = games_retro_runner_factory_get_instance_private (self);
}

static void
games_retro_runner_factory_finalize (GObject * obj)
{
	GamesRetroRunnerFactory * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GAMES_TYPE_RETRO_RUNNER_FACTORY, GamesRetroRunnerFactory);
	_g_object_unref0 (self->priv->platform);
	G_OBJECT_CLASS (games_retro_runner_factory_parent_class)->finalize (obj);
}

static GType
games_retro_runner_factory_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GamesRetroRunnerFactoryClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) games_retro_runner_factory_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GamesRetroRunnerFactory), 0, (GInstanceInitFunc) games_retro_runner_factory_instance_init, NULL };
	static const GInterfaceInfo games_runner_factory_info = { (GInterfaceInitFunc) games_retro_runner_factory_games_runner_factory_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	GType games_retro_runner_factory_type_id;
	games_retro_runner_factory_type_id = g_type_register_static (G_TYPE_OBJECT, "GamesRetroRunnerFactory", &g_define_type_info, 0);
	g_type_add_interface_static (games_retro_runner_factory_type_id, GAMES_TYPE_RUNNER_FACTORY, &games_runner_factory_info);
	GamesRetroRunnerFactory_private_offset = g_type_add_instance_private (games_retro_runner_factory_type_id, sizeof (GamesRetroRunnerFactoryPrivate));
	return games_retro_runner_factory_type_id;
}

GType
games_retro_runner_factory_get_type (void)
{
	static volatile gsize games_retro_runner_factory_type_id__once = 0;
	if (g_once_init_enter (&games_retro_runner_factory_type_id__once)) {
		GType games_retro_runner_factory_type_id;
		games_retro_runner_factory_type_id = games_retro_runner_factory_get_type_once ();
		g_once_init_leave (&games_retro_runner_factory_type_id__once, games_retro_runner_factory_type_id);
	}
	return games_retro_runner_factory_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;
}

