/* retro-simple-game-uri-adapter.c generated by valac 0.56.18-dirty, the Vala compiler
 * generated from retro-simple-game-uri-adapter.vala, do not modify */

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

#include <glib-object.h>
#include "gnome-games.h"
#include <stdlib.h>
#include <string.h>
#include <glib.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 GAMES_TYPE_RETRO_SIMPLE_GAME_URI_ADAPTER (games_retro_simple_game_uri_adapter_get_type ())
#define GAMES_RETRO_SIMPLE_GAME_URI_ADAPTER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_RETRO_SIMPLE_GAME_URI_ADAPTER, GamesRetroSimpleGameUriAdapter))
#define GAMES_RETRO_SIMPLE_GAME_URI_ADAPTER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAMES_TYPE_RETRO_SIMPLE_GAME_URI_ADAPTER, GamesRetroSimpleGameUriAdapterClass))
#define GAMES_IS_RETRO_SIMPLE_GAME_URI_ADAPTER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_RETRO_SIMPLE_GAME_URI_ADAPTER))
#define GAMES_IS_RETRO_SIMPLE_GAME_URI_ADAPTER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAMES_TYPE_RETRO_SIMPLE_GAME_URI_ADAPTER))
#define GAMES_RETRO_SIMPLE_GAME_URI_ADAPTER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GAMES_TYPE_RETRO_SIMPLE_GAME_URI_ADAPTER, GamesRetroSimpleGameUriAdapterClass))

typedef struct _GamesRetroSimpleGameUriAdapter GamesRetroSimpleGameUriAdapter;
typedef struct _GamesRetroSimpleGameUriAdapterClass GamesRetroSimpleGameUriAdapterClass;
typedef struct _GamesRetroSimpleGameUriAdapterPrivate GamesRetroSimpleGameUriAdapterPrivate;

#define GAMES_TYPE_RETRO_SIMPLE_TYPE (games_retro_simple_type_get_type ())
typedef struct _GamesRetroSimpleType GamesRetroSimpleType;
enum  {
	GAMES_RETRO_SIMPLE_GAME_URI_ADAPTER_0_PROPERTY,
	GAMES_RETRO_SIMPLE_GAME_URI_ADAPTER_NUM_PROPERTIES
};
static GParamSpec* games_retro_simple_game_uri_adapter_properties[GAMES_RETRO_SIMPLE_GAME_URI_ADAPTER_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))

struct _GamesRetroSimpleGameUriAdapter {
	GObject parent_instance;
	GamesRetroSimpleGameUriAdapterPrivate * priv;
};

struct _GamesRetroSimpleGameUriAdapterClass {
	GObjectClass parent_class;
};

struct _GamesRetroSimpleType {
	gchar* mime_type;
	gboolean search_mime_type;
	gchar* platform;
	gchar* prefix;
};

struct _GamesRetroSimpleGameUriAdapterPrivate {
	GamesRetroSimpleType simple_type;
	GamesRetroPlatform* platform;
};

static gint GamesRetroSimpleGameUriAdapter_private_offset;
static gpointer games_retro_simple_game_uri_adapter_parent_class = NULL;
static GamesGameUriAdapterIface * games_retro_simple_game_uri_adapter_games_game_uri_adapter_parent_iface = NULL;

VALA_EXTERN GType games_retro_simple_game_uri_adapter_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GType games_retro_simple_type_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GamesRetroSimpleType* games_retro_simple_type_dup (const GamesRetroSimpleType* self);
VALA_EXTERN void games_retro_simple_type_free (GamesRetroSimpleType* self);
VALA_EXTERN void games_retro_simple_type_copy (const GamesRetroSimpleType* self,
                                   GamesRetroSimpleType* dest);
VALA_EXTERN void games_retro_simple_type_destroy (GamesRetroSimpleType* self);
VALA_EXTERN GamesRetroSimpleGameUriAdapter* games_retro_simple_game_uri_adapter_new (GamesRetroSimpleType* simple_type,
                                                                         GamesRetroPlatform* platform);
VALA_EXTERN GamesRetroSimpleGameUriAdapter* games_retro_simple_game_uri_adapter_construct (GType object_type,
                                                                               GamesRetroSimpleType* simple_type,
                                                                               GamesRetroPlatform* platform);
static GamesGame* games_retro_simple_game_uri_adapter_real_game_for_uri (GamesGameUriAdapter* base,
                                                                  GamesUri* uri,
                                                                  GError** error);
static void games_retro_simple_game_uri_adapter_finalize (GObject * obj);
static GType games_retro_simple_game_uri_adapter_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_retro_simple_game_uri_adapter_get_instance_private (GamesRetroSimpleGameUriAdapter* self)
{
	return G_STRUCT_MEMBER_P (self, GamesRetroSimpleGameUriAdapter_private_offset);
}

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

GamesRetroSimpleGameUriAdapter*
games_retro_simple_game_uri_adapter_construct (GType object_type,
                                               GamesRetroSimpleType* simple_type,
                                               GamesRetroPlatform* platform)
{
	GamesRetroSimpleGameUriAdapter * self = NULL;
	GamesRetroSimpleType _tmp0_;
	GamesRetroSimpleType _tmp1_;
	GamesRetroSimpleType _tmp2_ = {0};
	GamesRetroPlatform* _tmp3_;
	g_return_val_if_fail (simple_type != NULL, NULL);
	g_return_val_if_fail (platform != NULL, NULL);
	self = (GamesRetroSimpleGameUriAdapter*) g_object_new (object_type, NULL);
	_tmp0_ = *simple_type;
	_tmp1_ = _tmp0_;
	games_retro_simple_type_copy (&_tmp1_, &_tmp2_);
	games_retro_simple_type_destroy (&self->priv->simple_type);
	self->priv->simple_type = _tmp2_;
	_tmp3_ = _g_object_ref0 (platform);
	_g_object_unref0 (self->priv->platform);
	self->priv->platform = _tmp3_;
	return self;
}

GamesRetroSimpleGameUriAdapter*
games_retro_simple_game_uri_adapter_new (GamesRetroSimpleType* simple_type,
                                         GamesRetroPlatform* platform)
{
	return games_retro_simple_game_uri_adapter_construct (GAMES_TYPE_RETRO_SIMPLE_GAME_URI_ADAPTER, simple_type, platform);
}

static GamesGame*
games_retro_simple_game_uri_adapter_real_game_for_uri (GamesGameUriAdapter* base,
                                                       GamesUri* uri,
                                                       GError** error)
{
	GamesRetroSimpleGameUriAdapter * self;
	gchar* _tmp0_ = NULL;
	GamesRetroSimpleType _tmp1_;
	const gchar* _tmp2_;
	gchar* _tmp3_;
	GamesUid* uid = NULL;
	GamesUid* _tmp4_;
	GamesFilenameTitle* title = NULL;
	GamesFilenameTitle* _tmp5_;
	GamesGriloMedia* media = NULL;
	GamesFilenameTitle* _tmp6_;
	GamesRetroSimpleType _tmp7_;
	const gchar* _tmp8_;
	GamesGriloMedia* _tmp9_;
	GamesCompositeCover* cover = NULL;
	GamesLocalCover* _tmp10_;
	GamesGriloMedia* _tmp11_;
	GamesUid* _tmp12_;
	GamesGriloCover* _tmp13_;
	GamesCover** _tmp14_;
	GamesCover** _tmp15_;
	gint _tmp15__length1;
	GamesCompositeCover* _tmp16_;
	GamesCompositeCover* _tmp17_;
	GamesGame* game = NULL;
	GamesUid* _tmp18_;
	GamesFilenameTitle* _tmp19_;
	GamesRetroPlatform* _tmp20_;
	GamesGame* _tmp21_;
	GamesGame* _tmp22_;
	GamesCompositeCover* _tmp23_;
	GError* _inner_error0_ = NULL;
	GamesGame* result;
	self = (GamesRetroSimpleGameUriAdapter*) base;
	g_return_val_if_fail (uri != NULL, NULL);
	_tmp1_ = self->priv->simple_type;
	_tmp2_ = _tmp1_.prefix;
	_tmp3_ = games_fingerprint_get_uid (uri, _tmp2_, &_inner_error0_);
	_tmp0_ = _tmp3_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		return NULL;
	}
	_tmp4_ = games_uid_new (_tmp0_);
	uid = _tmp4_;
	_tmp5_ = games_filename_title_new (uri);
	title = _tmp5_;
	_tmp6_ = title;
	_tmp7_ = self->priv->simple_type;
	_tmp8_ = _tmp7_.mime_type;
	_tmp9_ = games_grilo_media_new ((GamesTitle*) _tmp6_, _tmp8_);
	media = _tmp9_;
	_tmp10_ = games_local_cover_new (uri);
	_tmp11_ = media;
	_tmp12_ = uid;
	_tmp13_ = games_grilo_cover_new (_tmp11_, _tmp12_);
	_tmp14_ = g_new0 (GamesCover*, 2 + 1);
	_tmp14_[0] = (GamesCover*) _tmp10_;
	_tmp14_[1] = (GamesCover*) _tmp13_;
	_tmp15_ = _tmp14_;
	_tmp15__length1 = 2;
	_tmp16_ = games_composite_cover_new (_tmp15_, 2);
	_tmp17_ = _tmp16_;
	_tmp15_ = (_vala_array_free (_tmp15_, _tmp15__length1, (GDestroyNotify) g_object_unref), NULL);
	cover = _tmp17_;
	_tmp18_ = uid;
	_tmp19_ = title;
	_tmp20_ = self->priv->platform;
	_tmp21_ = games_game_new (_tmp18_, uri, (GamesTitle*) _tmp19_, (GamesPlatform*) _tmp20_);
	game = _tmp21_;
	_tmp22_ = game;
	_tmp23_ = cover;
	games_game_set_cover (_tmp22_, (GamesCover*) _tmp23_);
	result = game;
	_g_object_unref0 (cover);
	_g_object_unref0 (media);
	_g_object_unref0 (title);
	_g_object_unref0 (uid);
	_g_free0 (_tmp0_);
	return result;
}

static void
games_retro_simple_game_uri_adapter_class_init (GamesRetroSimpleGameUriAdapterClass * klass,
                                                gpointer klass_data)
{
	games_retro_simple_game_uri_adapter_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &GamesRetroSimpleGameUriAdapter_private_offset);
	G_OBJECT_CLASS (klass)->finalize = games_retro_simple_game_uri_adapter_finalize;
}

static void
games_retro_simple_game_uri_adapter_games_game_uri_adapter_interface_init (GamesGameUriAdapterIface * iface,
                                                                           gpointer iface_data)
{
	games_retro_simple_game_uri_adapter_games_game_uri_adapter_parent_iface = g_type_interface_peek_parent (iface);
	iface->game_for_uri = (GamesGame* (*) (GamesGameUriAdapter*, GamesUri*, GError**)) games_retro_simple_game_uri_adapter_real_game_for_uri;
}

static void
games_retro_simple_game_uri_adapter_instance_init (GamesRetroSimpleGameUriAdapter * self,
                                                   gpointer klass)
{
	self->priv = games_retro_simple_game_uri_adapter_get_instance_private (self);
}

static void
games_retro_simple_game_uri_adapter_finalize (GObject * obj)
{
	GamesRetroSimpleGameUriAdapter * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GAMES_TYPE_RETRO_SIMPLE_GAME_URI_ADAPTER, GamesRetroSimpleGameUriAdapter);
	games_retro_simple_type_destroy (&self->priv->simple_type);
	_g_object_unref0 (self->priv->platform);
	G_OBJECT_CLASS (games_retro_simple_game_uri_adapter_parent_class)->finalize (obj);
}

static GType
games_retro_simple_game_uri_adapter_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GamesRetroSimpleGameUriAdapterClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) games_retro_simple_game_uri_adapter_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GamesRetroSimpleGameUriAdapter), 0, (GInstanceInitFunc) games_retro_simple_game_uri_adapter_instance_init, NULL };
	static const GInterfaceInfo games_game_uri_adapter_info = { (GInterfaceInitFunc) games_retro_simple_game_uri_adapter_games_game_uri_adapter_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	GType games_retro_simple_game_uri_adapter_type_id;
	games_retro_simple_game_uri_adapter_type_id = g_type_register_static (G_TYPE_OBJECT, "GamesRetroSimpleGameUriAdapter", &g_define_type_info, 0);
	g_type_add_interface_static (games_retro_simple_game_uri_adapter_type_id, GAMES_TYPE_GAME_URI_ADAPTER, &games_game_uri_adapter_info);
	GamesRetroSimpleGameUriAdapter_private_offset = g_type_add_instance_private (games_retro_simple_game_uri_adapter_type_id, sizeof (GamesRetroSimpleGameUriAdapterPrivate));
	return games_retro_simple_game_uri_adapter_type_id;
}

GType
games_retro_simple_game_uri_adapter_get_type (void)
{
	static volatile gsize games_retro_simple_game_uri_adapter_type_id__once = 0;
	if (g_once_init_enter (&games_retro_simple_game_uri_adapter_type_id__once)) {
		GType games_retro_simple_game_uri_adapter_type_id;
		games_retro_simple_game_uri_adapter_type_id = games_retro_simple_game_uri_adapter_get_type_once ();
		g_once_init_leave (&games_retro_simple_game_uri_adapter_type_id__once, games_retro_simple_game_uri_adapter_type_id);
	}
	return games_retro_simple_game_uri_adapter_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;
}

