/* game-boy-advance-plugin.c generated by valac 0.35.5, the Vala compiler
 * generated from game-boy-advance-plugin.vala, do not modify */

/* This file is part of GNOME Games. License: GPLv3*/

#include <glib.h>
#include <glib-object.h>
#include <libgnome-games.h>
#include <stdlib.h>
#include <string.h>
#include <libtracker-sparql/tracker-sparql.h>


#define GAMES_TYPE_GAME_BOY_ADVANCE_PLUGIN (games_game_boy_advance_plugin_get_type ())
#define GAMES_GAME_BOY_ADVANCE_PLUGIN(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_GAME_BOY_ADVANCE_PLUGIN, GamesGameBoyAdvancePlugin))
#define GAMES_GAME_BOY_ADVANCE_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAMES_TYPE_GAME_BOY_ADVANCE_PLUGIN, GamesGameBoyAdvancePluginClass))
#define GAMES_IS_GAME_BOY_ADVANCE_PLUGIN(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_GAME_BOY_ADVANCE_PLUGIN))
#define GAMES_IS_GAME_BOY_ADVANCE_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAMES_TYPE_GAME_BOY_ADVANCE_PLUGIN))
#define GAMES_GAME_BOY_ADVANCE_PLUGIN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GAMES_TYPE_GAME_BOY_ADVANCE_PLUGIN, GamesGameBoyAdvancePluginClass))

typedef struct _GamesGameBoyAdvancePlugin GamesGameBoyAdvancePlugin;
typedef struct _GamesGameBoyAdvancePluginClass GamesGameBoyAdvancePluginClass;
typedef struct _GamesGameBoyAdvancePluginPrivate GamesGameBoyAdvancePluginPrivate;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

struct _GamesGameBoyAdvancePlugin {
	GObject parent_instance;
	GamesGameBoyAdvancePluginPrivate * priv;
};

struct _GamesGameBoyAdvancePluginClass {
	GObjectClass parent_class;
};


static gpointer games_game_boy_advance_plugin_parent_class = NULL;
static GamesPluginIface * games_game_boy_advance_plugin_games_plugin_parent_iface = NULL;
static GType games_game_boy_advance_plugin_type_id = 0;

GType games_game_boy_advance_plugin_get_type (void) G_GNUC_CONST;
enum  {
	GAMES_GAME_BOY_ADVANCE_PLUGIN_DUMMY_PROPERTY
};
#define GAMES_GAME_BOY_ADVANCE_PLUGIN_FINGERPRINT_PREFIX "game-boy-advance"
#define GAMES_GAME_BOY_ADVANCE_PLUGIN_MIME_TYPE "application/x-gba-rom"
#define GAMES_GAME_BOY_ADVANCE_PLUGIN_PLATFORM "GameBoyAdvance"
static GamesGameSource* games_game_boy_advance_plugin_real_get_game_source (GamesPlugin* base, GError** error);
static GamesGame* games_game_boy_advance_plugin_game_for_uri (const gchar* uri, GError** error);
static GamesGame* _games_game_boy_advance_plugin_game_for_uri_games_generic_sync_game_uri_adapter_game_for_uri (const gchar* uri, gpointer self, GError** error);
GamesGameBoyAdvancePlugin* games_game_boy_advance_plugin_new (void);
GamesGameBoyAdvancePlugin* games_game_boy_advance_plugin_construct (GType object_type);
GType register_games_plugin (GTypeModule* module);
GType games_game_boy_advance_plugin_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 GamesGame* _games_game_boy_advance_plugin_game_for_uri_games_generic_sync_game_uri_adapter_game_for_uri (const gchar* uri, gpointer self, GError** error) {
	GamesGame* result;
	result = games_game_boy_advance_plugin_game_for_uri (uri, error);
	return result;
}


static GamesGameSource* games_game_boy_advance_plugin_real_get_game_source (GamesPlugin* base, GError** error) {
	GamesGameBoyAdvancePlugin * self;
	GamesGameSource* result = NULL;
	GamesGenericSyncGameUriAdapter* game_uri_adapter;
	GamesGenericSyncGameUriAdapter* _tmp0_;
	GamesGenericUriGameFactory* factory;
	GamesGenericUriGameFactory* _tmp1_;
	GamesMimeTypeTrackerQuery* query;
	GamesMimeTypeTrackerQuery* _tmp2_;
	TrackerSparqlConnection* connection;
	TrackerSparqlConnection* _tmp3_;
	GamesTrackerGameSource* source;
	GamesTrackerGameSource* _tmp4_;
	GamesTrackerGameSource* _tmp5_;
	GError * _inner_error_ = NULL;
	self = (GamesGameBoyAdvancePlugin*) base;
	_tmp0_ = games_generic_sync_game_uri_adapter_new (_games_game_boy_advance_plugin_game_for_uri_games_generic_sync_game_uri_adapter_game_for_uri, NULL, NULL);
	game_uri_adapter = _tmp0_;
	_tmp1_ = games_generic_uri_game_factory_new ((GamesGameUriAdapter*) game_uri_adapter, NULL, NULL, NULL);
	factory = _tmp1_;
	_tmp2_ = games_mime_type_tracker_query_new (GAMES_GAME_BOY_ADVANCE_PLUGIN_MIME_TYPE, (GamesUriGameFactory*) factory);
	query = _tmp2_;
	_tmp3_ = tracker_sparql_connection_get (NULL, &_inner_error_);
	connection = _tmp3_;
	if (G_UNLIKELY (_inner_error_ != NULL)) {
		g_propagate_error (error, _inner_error_);
		_g_object_unref0 (query);
		_g_object_unref0 (factory);
		_g_object_unref0 (game_uri_adapter);
		return NULL;
	}
	_tmp4_ = games_tracker_game_source_new (connection);
	source = _tmp4_;
	_tmp5_ = source;
	games_tracker_game_source_add_query (_tmp5_, (GamesTrackerQuery*) query);
	result = (GamesGameSource*) source;
	_g_object_unref0 (connection);
	_g_object_unref0 (query);
	_g_object_unref0 (factory);
	_g_object_unref0 (game_uri_adapter);
	return result;
}


static GamesGame* games_game_boy_advance_plugin_game_for_uri (const gchar* uri, GError** error) {
	GamesGame* result = NULL;
	GamesFingerprintUid* uid;
	const gchar* _tmp0_;
	GamesFingerprintUid* _tmp1_;
	GamesFilenameTitle* title;
	const gchar* _tmp2_;
	GamesFilenameTitle* _tmp3_;
	GamesDummyIcon* icon;
	GamesDummyIcon* _tmp4_;
	GamesGriloMedia* media;
	GamesGriloMedia* _tmp5_;
	GamesCompositeCover* cover;
	const gchar* _tmp6_;
	GamesLocalCover* _tmp7_;
	GamesGriloCover* _tmp8_;
	GamesCover** _tmp9_;
	GamesCover** _tmp10_;
	gint _tmp10__length1;
	GamesCompositeCover* _tmp11_;
	GamesCompositeCover* _tmp12_;
	GamesRetroCoreSource* core_source;
	gchar* _tmp13_;
	gchar** _tmp14_;
	gchar** _tmp15_;
	gint _tmp15__length1;
	GamesRetroCoreSource* _tmp16_;
	GamesRetroCoreSource* _tmp17_;
	GamesRetroRunner* runner;
	const gchar* _tmp18_;
	GamesRetroRunner* _tmp19_;
	GamesGenericGame* _tmp20_;
	g_return_val_if_fail (uri != NULL, NULL);
	_tmp0_ = uri;
	_tmp1_ = games_fingerprint_uid_new (_tmp0_, GAMES_GAME_BOY_ADVANCE_PLUGIN_FINGERPRINT_PREFIX);
	uid = _tmp1_;
	_tmp2_ = uri;
	_tmp3_ = games_filename_title_new (_tmp2_);
	title = _tmp3_;
	_tmp4_ = games_dummy_icon_new ();
	icon = _tmp4_;
	_tmp5_ = games_grilo_media_new ((GamesTitle*) title, GAMES_GAME_BOY_ADVANCE_PLUGIN_MIME_TYPE);
	media = _tmp5_;
	_tmp6_ = uri;
	_tmp7_ = games_local_cover_new (_tmp6_);
	_tmp8_ = games_grilo_cover_new (media, (GamesUid*) uid);
	_tmp9_ = g_new0 (GamesCover*, 2 + 1);
	_tmp9_[0] = (GamesCover*) _tmp7_;
	_tmp9_[1] = (GamesCover*) _tmp8_;
	_tmp10_ = _tmp9_;
	_tmp10__length1 = 2;
	_tmp11_ = games_composite_cover_new (_tmp10_, 2);
	_tmp12_ = _tmp11_;
	_tmp10_ = (_vala_array_free (_tmp10_, _tmp10__length1, (GDestroyNotify) g_object_unref), NULL);
	cover = _tmp12_;
	_tmp13_ = g_strdup (GAMES_GAME_BOY_ADVANCE_PLUGIN_MIME_TYPE);
	_tmp14_ = g_new0 (gchar*, 1 + 1);
	_tmp14_[0] = _tmp13_;
	_tmp15_ = _tmp14_;
	_tmp15__length1 = 1;
	_tmp16_ = games_retro_core_source_new (GAMES_GAME_BOY_ADVANCE_PLUGIN_PLATFORM, _tmp15_, 1);
	_tmp17_ = _tmp16_;
	_tmp15_ = (_vala_array_free (_tmp15_, _tmp15__length1, (GDestroyNotify) g_free), NULL);
	core_source = _tmp17_;
	_tmp18_ = uri;
	_tmp19_ = games_retro_runner_new (core_source, _tmp18_, (GamesUid*) uid, (GamesTitle*) title);
	runner = _tmp19_;
	_tmp20_ = games_generic_game_new ((GamesTitle*) title, (GamesIcon*) icon, (GamesCover*) cover, (GamesRunner*) runner);
	result = (GamesGame*) _tmp20_;
	_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);
	return result;
}


GamesGameBoyAdvancePlugin* games_game_boy_advance_plugin_construct (GType object_type) {
	GamesGameBoyAdvancePlugin * self = NULL;
	self = (GamesGameBoyAdvancePlugin*) g_object_new (object_type, NULL);
	return self;
}


GamesGameBoyAdvancePlugin* games_game_boy_advance_plugin_new (void) {
	return games_game_boy_advance_plugin_construct (GAMES_TYPE_GAME_BOY_ADVANCE_PLUGIN);
}


static void games_game_boy_advance_plugin_class_init (GamesGameBoyAdvancePluginClass * klass) {
	games_game_boy_advance_plugin_parent_class = g_type_class_peek_parent (klass);
}


static void games_game_boy_advance_plugin_games_plugin_interface_init (GamesPluginIface * iface) {
	games_game_boy_advance_plugin_games_plugin_parent_iface = g_type_interface_peek_parent (iface);
	iface->get_game_source = (GamesGameSource* (*) (GamesPlugin *, GError**)) games_game_boy_advance_plugin_real_get_game_source;
}


static void games_game_boy_advance_plugin_instance_init (GamesGameBoyAdvancePlugin * self) {
}


GType games_game_boy_advance_plugin_get_type (void) {
	return games_game_boy_advance_plugin_type_id;
}


GType games_game_boy_advance_plugin_register_type (GTypeModule * module) {
	static const GTypeInfo g_define_type_info = { sizeof (GamesGameBoyAdvancePluginClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) games_game_boy_advance_plugin_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GamesGameBoyAdvancePlugin), 0, (GInstanceInitFunc) games_game_boy_advance_plugin_instance_init, NULL };
	static const GInterfaceInfo games_plugin_info = { (GInterfaceInitFunc) games_game_boy_advance_plugin_games_plugin_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	games_game_boy_advance_plugin_type_id = g_type_module_register_type (module, G_TYPE_OBJECT, "GamesGameBoyAdvancePlugin", &g_define_type_info, 0);
	g_type_module_add_interface (module, games_game_boy_advance_plugin_type_id, GAMES_TYPE_PLUGIN, &games_plugin_info);
	return games_game_boy_advance_plugin_type_id;
}


GType register_games_plugin (GTypeModule* module) {
	GType result = 0UL;
	g_return_val_if_fail (module != NULL, 0UL);
	games_game_boy_advance_plugin_register_type (module);
	result = GAMES_TYPE_GAME_BOY_ADVANCE_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);
}



