/* dreamcast-plugin.c generated by valac 0.36.9, the Vala compiler
 * generated from dreamcast-plugin.vala, do not modify */

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

#include <glib.h>
#include <glib-object.h>
#include <libgnome-games.h>
#include <stdlib.h>
#include <string.h>
#include <gio/gio.h>


#define GAMES_TYPE_DREAMCAST_PLUGIN (games_dreamcast_plugin_get_type ())
#define GAMES_DREAMCAST_PLUGIN(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_DREAMCAST_PLUGIN, GamesDreamcastPlugin))
#define GAMES_DREAMCAST_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAMES_TYPE_DREAMCAST_PLUGIN, GamesDreamcastPluginClass))
#define GAMES_IS_DREAMCAST_PLUGIN(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_DREAMCAST_PLUGIN))
#define GAMES_IS_DREAMCAST_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAMES_TYPE_DREAMCAST_PLUGIN))
#define GAMES_DREAMCAST_PLUGIN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GAMES_TYPE_DREAMCAST_PLUGIN, GamesDreamcastPluginClass))

typedef struct _GamesDreamcastPlugin GamesDreamcastPlugin;
typedef struct _GamesDreamcastPluginClass GamesDreamcastPluginClass;
typedef struct _GamesDreamcastPluginPrivate GamesDreamcastPluginPrivate;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

#define GAMES_TYPE_DREAMCAST_HEADER (games_dreamcast_header_get_type ())
#define GAMES_DREAMCAST_HEADER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_DREAMCAST_HEADER, GamesDreamcastHeader))
#define GAMES_DREAMCAST_HEADER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAMES_TYPE_DREAMCAST_HEADER, GamesDreamcastHeaderClass))
#define GAMES_IS_DREAMCAST_HEADER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_DREAMCAST_HEADER))
#define GAMES_IS_DREAMCAST_HEADER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAMES_TYPE_DREAMCAST_HEADER))
#define GAMES_DREAMCAST_HEADER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GAMES_TYPE_DREAMCAST_HEADER, GamesDreamcastHeaderClass))

typedef struct _GamesDreamcastHeader GamesDreamcastHeader;
typedef struct _GamesDreamcastHeaderClass GamesDreamcastHeaderClass;

#define GAMES_TYPE_DREAMCAST_UID (games_dreamcast_uid_get_type ())
#define GAMES_DREAMCAST_UID(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_DREAMCAST_UID, GamesDreamcastUid))
#define GAMES_DREAMCAST_UID_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAMES_TYPE_DREAMCAST_UID, GamesDreamcastUidClass))
#define GAMES_IS_DREAMCAST_UID(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_DREAMCAST_UID))
#define GAMES_IS_DREAMCAST_UID_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAMES_TYPE_DREAMCAST_UID))
#define GAMES_DREAMCAST_UID_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GAMES_TYPE_DREAMCAST_UID, GamesDreamcastUidClass))

typedef struct _GamesDreamcastUid GamesDreamcastUid;
typedef struct _GamesDreamcastUidClass GamesDreamcastUidClass;

struct _GamesDreamcastPlugin {
	GObject parent_instance;
	GamesDreamcastPluginPrivate * priv;
};

struct _GamesDreamcastPluginClass {
	GObjectClass parent_class;
};


static gpointer games_dreamcast_plugin_parent_class = NULL;
static GamesPluginIface * games_dreamcast_plugin_games_plugin_parent_iface = NULL;
static GType games_dreamcast_plugin_type_id = 0;

GType games_dreamcast_plugin_get_type (void) G_GNUC_CONST;
enum  {
	GAMES_DREAMCAST_PLUGIN_0_PROPERTY
};
#define GAMES_DREAMCAST_PLUGIN_MIME_TYPE "application/x-dc-rom"
#define GAMES_DREAMCAST_PLUGIN_PLATFORM "Dreamcast"
static gchar** games_dreamcast_plugin_real_get_mime_types (GamesPlugin* base, int* result_length1);
static GamesUriGameFactory** games_dreamcast_plugin_real_get_uri_game_factories (GamesPlugin* base, int* result_length1);
static GamesGame* games_dreamcast_plugin_game_for_uri (GamesUri* uri, GError** error);
static GamesGame* _games_dreamcast_plugin_game_for_uri_games_generic_game_uri_adapter_game_for_uri (GamesUri* uri, gpointer self, GError** error);
GType games_dreamcast_header_get_type (void) G_GNUC_CONST;
GamesDreamcastHeader* games_dreamcast_header_new (GFile* file);
GamesDreamcastHeader* games_dreamcast_header_construct (GType object_type, GFile* file);
void games_dreamcast_header_check_validity (GamesDreamcastHeader* self, GError** error);
GType games_dreamcast_uid_get_type (void) G_GNUC_CONST;
GamesDreamcastUid* games_dreamcast_uid_new (GamesDreamcastHeader* header);
GamesDreamcastUid* games_dreamcast_uid_construct (GType object_type, GamesDreamcastHeader* header);
GamesDreamcastPlugin* games_dreamcast_plugin_new (void);
GamesDreamcastPlugin* games_dreamcast_plugin_construct (GType object_type);
GType register_games_plugin (GTypeModule* module);
GType games_dreamcast_header_register_type (GTypeModule * module);
GType games_dreamcast_plugin_register_type (GTypeModule * module);
GType games_dreamcast_uid_register_type (GTypeModule * module);
static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array, gint array_length, GDestroyNotify destroy_func);


static gchar** games_dreamcast_plugin_real_get_mime_types (GamesPlugin* base, int* result_length1) {
	GamesDreamcastPlugin * self;
	gchar** result = NULL;
	gchar* _tmp0_;
	gchar** _tmp1_;
	gchar** _tmp2_;
	gint _tmp2__length1;
	self = (GamesDreamcastPlugin*) base;
	_tmp0_ = g_strdup (GAMES_DREAMCAST_PLUGIN_MIME_TYPE);
	_tmp1_ = g_new0 (gchar*, 1 + 1);
	_tmp1_[0] = _tmp0_;
	_tmp2_ = _tmp1_;
	_tmp2__length1 = 1;
	if (result_length1) {
		*result_length1 = _tmp2__length1;
	}
	result = _tmp2_;
	return result;
}


static GamesGame* _games_dreamcast_plugin_game_for_uri_games_generic_game_uri_adapter_game_for_uri (GamesUri* uri, gpointer self, GError** error) {
	GamesGame* result;
	result = games_dreamcast_plugin_game_for_uri (uri, error);
	return result;
}


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


static GamesUriGameFactory** games_dreamcast_plugin_real_get_uri_game_factories (GamesPlugin* base, int* result_length1) {
	GamesDreamcastPlugin * self;
	GamesUriGameFactory** result = NULL;
	GamesGenericGameUriAdapter* game_uri_adapter = NULL;
	GamesGenericGameUriAdapter* _tmp0_;
	GamesGenericUriGameFactory* factory = NULL;
	GamesGenericUriGameFactory* _tmp1_;
	GamesUriGameFactory* _tmp2_;
	GamesUriGameFactory** _tmp3_;
	GamesUriGameFactory** _tmp4_;
	gint _tmp4__length1;
	self = (GamesDreamcastPlugin*) base;
	_tmp0_ = games_generic_game_uri_adapter_new (_games_dreamcast_plugin_game_for_uri_games_generic_game_uri_adapter_game_for_uri, NULL, NULL);
	game_uri_adapter = _tmp0_;
	_tmp1_ = games_generic_uri_game_factory_new ((GamesGameUriAdapter*) game_uri_adapter);
	factory = _tmp1_;
	games_generic_uri_game_factory_add_mime_type (factory, GAMES_DREAMCAST_PLUGIN_MIME_TYPE);
	_tmp2_ = _g_object_ref0 ((GamesUriGameFactory*) factory);
	_tmp3_ = g_new0 (GamesUriGameFactory*, 1 + 1);
	_tmp3_[0] = _tmp2_;
	_tmp4_ = _tmp3_;
	_tmp4__length1 = 1;
	if (result_length1) {
		*result_length1 = _tmp4__length1;
	}
	result = _tmp4_;
	_g_object_unref0 (factory);
	_g_object_unref0 (game_uri_adapter);
	return result;
}


static GamesGame* games_dreamcast_plugin_game_for_uri (GamesUri* uri, GError** error) {
	GamesGame* result = NULL;
	GFile* file = NULL;
	GamesUri* _tmp0_;
	GFile* _tmp1_;
	GamesDreamcastHeader* header = NULL;
	GamesDreamcastHeader* _tmp2_;
	GamesDreamcastUid* uid = NULL;
	GamesDreamcastUid* _tmp3_;
	GamesFilenameTitle* title = NULL;
	GamesUri* _tmp4_;
	GamesFilenameTitle* _tmp5_;
	GamesDummyIcon* icon = NULL;
	GamesDummyIcon* _tmp6_;
	GamesGriloMedia* media = NULL;
	GamesFilenameTitle* _tmp7_;
	GamesGriloMedia* _tmp8_;
	GamesCompositeCover* cover = NULL;
	GamesUri* _tmp9_;
	GamesLocalCover* _tmp10_;
	GamesGriloMedia* _tmp11_;
	GamesDreamcastUid* _tmp12_;
	GamesGriloCover* _tmp13_;
	GamesCover** _tmp14_;
	GamesCover** _tmp15_;
	gint _tmp15__length1;
	GamesCompositeCover* _tmp16_;
	GamesCompositeCover* _tmp17_;
	GamesRetroCoreSource* core_source = NULL;
	gchar* _tmp18_;
	gchar** _tmp19_;
	gchar** _tmp20_;
	gint _tmp20__length1;
	GamesRetroCoreSource* _tmp21_;
	GamesRetroCoreSource* _tmp22_;
	GamesRetroRunner* runner = NULL;
	GamesRetroCoreSource* _tmp23_;
	GamesUri* _tmp24_;
	GamesDreamcastUid* _tmp25_;
	GamesFilenameTitle* _tmp26_;
	GamesRetroRunner* _tmp27_;
	GamesFilenameTitle* _tmp28_;
	GamesDummyIcon* _tmp29_;
	GamesCompositeCover* _tmp30_;
	GamesRetroRunner* _tmp31_;
	GamesGenericGame* _tmp32_;
	GError * _inner_error_ = NULL;
	g_return_val_if_fail (uri != NULL, NULL);
	_tmp0_ = uri;
	_tmp1_ = games_uri_to_file (_tmp0_);
	file = _tmp1_;
	_tmp2_ = games_dreamcast_header_new (file);
	header = _tmp2_;
	games_dreamcast_header_check_validity (header, &_inner_error_);
	if (G_UNLIKELY (_inner_error_ != NULL)) {
		g_propagate_error (error, _inner_error_);
		_g_object_unref0 (header);
		_g_object_unref0 (file);
		return NULL;
	}
	_tmp3_ = games_dreamcast_uid_new (header);
	uid = _tmp3_;
	_tmp4_ = uri;
	_tmp5_ = games_filename_title_new (_tmp4_);
	title = _tmp5_;
	_tmp6_ = games_dummy_icon_new ();
	icon = _tmp6_;
	_tmp7_ = title;
	_tmp8_ = games_grilo_media_new ((GamesTitle*) _tmp7_, GAMES_DREAMCAST_PLUGIN_MIME_TYPE);
	media = _tmp8_;
	_tmp9_ = uri;
	_tmp10_ = games_local_cover_new (_tmp9_);
	_tmp11_ = media;
	_tmp12_ = uid;
	_tmp13_ = games_grilo_cover_new (_tmp11_, (GamesUid*) _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_ = g_strdup (GAMES_DREAMCAST_PLUGIN_MIME_TYPE);
	_tmp19_ = g_new0 (gchar*, 1 + 1);
	_tmp19_[0] = _tmp18_;
	_tmp20_ = _tmp19_;
	_tmp20__length1 = 1;
	_tmp21_ = games_retro_core_source_new (GAMES_DREAMCAST_PLUGIN_PLATFORM, _tmp20_, 1);
	_tmp22_ = _tmp21_;
	_tmp20_ = (_vala_array_free (_tmp20_, _tmp20__length1, (GDestroyNotify) g_free), NULL);
	core_source = _tmp22_;
	_tmp23_ = core_source;
	_tmp24_ = uri;
	_tmp25_ = uid;
	_tmp26_ = title;
	_tmp27_ = games_retro_runner_new (_tmp23_, _tmp24_, (GamesUid*) _tmp25_, (GamesTitle*) _tmp26_);
	runner = _tmp27_;
	_tmp28_ = title;
	_tmp29_ = icon;
	_tmp30_ = cover;
	_tmp31_ = runner;
	_tmp32_ = games_generic_game_new ((GamesTitle*) _tmp28_, (GamesIcon*) _tmp29_, (GamesCover*) _tmp30_, (GamesRunner*) _tmp31_);
	result = (GamesGame*) _tmp32_;
	_g_object_unref0 (runner);
	_g_object_unref0 (core_source);
	_g_object_unref0 (cover);
	_g_object_unref0 (media);
	_g_object_unref0 (icon);
	_g_object_unref0 (title);
	_g_object_unref0 (uid);
	_g_object_unref0 (header);
	_g_object_unref0 (file);
	return result;
}


GamesDreamcastPlugin* games_dreamcast_plugin_construct (GType object_type) {
	GamesDreamcastPlugin * self = NULL;
	self = (GamesDreamcastPlugin*) g_object_new (object_type, NULL);
	return self;
}


GamesDreamcastPlugin* games_dreamcast_plugin_new (void) {
	return games_dreamcast_plugin_construct (GAMES_TYPE_DREAMCAST_PLUGIN);
}


static void games_dreamcast_plugin_class_init (GamesDreamcastPluginClass * klass) {
	games_dreamcast_plugin_parent_class = g_type_class_peek_parent (klass);
}


static void games_dreamcast_plugin_games_plugin_interface_init (GamesPluginIface * iface) {
	games_dreamcast_plugin_games_plugin_parent_iface = g_type_interface_peek_parent (iface);
	iface->get_mime_types = (gchar** (*) (GamesPlugin *, int*)) games_dreamcast_plugin_real_get_mime_types;
	iface->get_uri_game_factories = (GamesUriGameFactory** (*) (GamesPlugin *, int*)) games_dreamcast_plugin_real_get_uri_game_factories;
}


static void games_dreamcast_plugin_instance_init (GamesDreamcastPlugin * self) {
}


GType games_dreamcast_plugin_get_type (void) {
	return games_dreamcast_plugin_type_id;
}


GType games_dreamcast_plugin_register_type (GTypeModule * module) {
	static const GTypeInfo g_define_type_info = { sizeof (GamesDreamcastPluginClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) games_dreamcast_plugin_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GamesDreamcastPlugin), 0, (GInstanceInitFunc) games_dreamcast_plugin_instance_init, NULL };
	static const GInterfaceInfo games_plugin_info = { (GInterfaceInitFunc) games_dreamcast_plugin_games_plugin_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	games_dreamcast_plugin_type_id = g_type_module_register_type (module, G_TYPE_OBJECT, "GamesDreamcastPlugin", &g_define_type_info, 0);
	g_type_module_add_interface (module, games_dreamcast_plugin_type_id, GAMES_TYPE_PLUGIN, &games_plugin_info);
	return games_dreamcast_plugin_type_id;
}


GType register_games_plugin (GTypeModule* module) {
	GType result = 0UL;
	g_return_val_if_fail (module != NULL, 0UL);
	games_dreamcast_header_register_type (module);
	games_dreamcast_plugin_register_type (module);
	games_dreamcast_uid_register_type (module);
	result = GAMES_TYPE_DREAMCAST_PLUGIN;
	return result;
}


static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func) {
	if ((array != NULL) && (destroy_func != NULL)) {
		int 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, gint array_length, GDestroyNotify destroy_func) {
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}



