/* mame-plugin.c generated by valac 0.35.5, the Vala compiler
 * generated from mame-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_MAME_PLUGIN (games_mame_plugin_get_type ())
#define GAMES_MAME_PLUGIN(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_MAME_PLUGIN, GamesMamePlugin))
#define GAMES_MAME_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAMES_TYPE_MAME_PLUGIN, GamesMamePluginClass))
#define GAMES_IS_MAME_PLUGIN(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_MAME_PLUGIN))
#define GAMES_IS_MAME_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAMES_TYPE_MAME_PLUGIN))
#define GAMES_MAME_PLUGIN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GAMES_TYPE_MAME_PLUGIN, GamesMamePluginClass))

typedef struct _GamesMamePlugin GamesMamePlugin;
typedef struct _GamesMamePluginClass GamesMamePluginClass;
typedef struct _GamesMamePluginPrivate GamesMamePluginPrivate;

#define GAMES_TYPE_MAME_GAME_URI_ADAPTER (games_mame_game_uri_adapter_get_type ())
#define GAMES_MAME_GAME_URI_ADAPTER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_MAME_GAME_URI_ADAPTER, GamesMameGameUriAdapter))
#define GAMES_MAME_GAME_URI_ADAPTER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAMES_TYPE_MAME_GAME_URI_ADAPTER, GamesMameGameUriAdapterClass))
#define GAMES_IS_MAME_GAME_URI_ADAPTER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_MAME_GAME_URI_ADAPTER))
#define GAMES_IS_MAME_GAME_URI_ADAPTER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAMES_TYPE_MAME_GAME_URI_ADAPTER))
#define GAMES_MAME_GAME_URI_ADAPTER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GAMES_TYPE_MAME_GAME_URI_ADAPTER, GamesMameGameUriAdapterClass))

typedef struct _GamesMameGameUriAdapter GamesMameGameUriAdapter;
typedef struct _GamesMameGameUriAdapterClass GamesMameGameUriAdapterClass;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

struct _GamesMamePlugin {
	GObject parent_instance;
	GamesMamePluginPrivate * priv;
};

struct _GamesMamePluginClass {
	GObjectClass parent_class;
};


static gpointer games_mame_plugin_parent_class = NULL;
static GamesPluginIface * games_mame_plugin_games_plugin_parent_iface = NULL;
static GType games_mame_plugin_type_id = 0;

GType games_mame_plugin_get_type (void) G_GNUC_CONST;
enum  {
	GAMES_MAME_PLUGIN_DUMMY_PROPERTY
};
#define GAMES_MAME_PLUGIN_SEARCHED_MIME_TYPE "application/zip"
static GamesGameSource* games_mame_plugin_real_get_game_source (GamesPlugin* base, GError** error);
GType games_mame_game_uri_adapter_get_type (void) G_GNUC_CONST;
GamesMameGameUriAdapter* games_mame_game_uri_adapter_new (void);
GamesMameGameUriAdapter* games_mame_game_uri_adapter_construct (GType object_type);
GamesMamePlugin* games_mame_plugin_new (void);
GamesMamePlugin* games_mame_plugin_construct (GType object_type);
GType register_games_plugin (GTypeModule* module);
GType games_mame_game_uri_adapter_register_type (GTypeModule * module);
GType games_mame_plugin_register_type (GTypeModule * module);


static GamesGameSource* games_mame_plugin_real_get_game_source (GamesPlugin* base, GError** error) {
	GamesMamePlugin * self;
	GamesGameSource* result = NULL;
	GamesMameGameUriAdapter* game_uri_adapter;
	GamesMameGameUriAdapter* _tmp0_;
	GamesGenericUriGameFactory* factory;
	GamesGenericUriGameFactory* _tmp1_;
	GamesMimeTypeTrackerQuery* query;
	GamesMimeTypeTrackerQuery* _tmp2_;
	TrackerSparqlConnection* connection;
	TrackerSparqlConnection* _tmp3_;
	GamesTrackerGameSource* source;
	GamesTrackerGameSource* _tmp4_;
	GamesTrackerGameSource* _tmp5_;
	GError * _inner_error_ = NULL;
	self = (GamesMamePlugin*) base;
	_tmp0_ = games_mame_game_uri_adapter_new ();
	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_MAME_PLUGIN_SEARCHED_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;
}


GamesMamePlugin* games_mame_plugin_construct (GType object_type) {
	GamesMamePlugin * self = NULL;
	self = (GamesMamePlugin*) g_object_new (object_type, NULL);
	return self;
}


GamesMamePlugin* games_mame_plugin_new (void) {
	return games_mame_plugin_construct (GAMES_TYPE_MAME_PLUGIN);
}


static void games_mame_plugin_class_init (GamesMamePluginClass * klass) {
	games_mame_plugin_parent_class = g_type_class_peek_parent (klass);
}


static void games_mame_plugin_games_plugin_interface_init (GamesPluginIface * iface) {
	games_mame_plugin_games_plugin_parent_iface = g_type_interface_peek_parent (iface);
	iface->get_game_source = (GamesGameSource* (*) (GamesPlugin *, GError**)) games_mame_plugin_real_get_game_source;
}


static void games_mame_plugin_instance_init (GamesMamePlugin * self) {
}


GType games_mame_plugin_get_type (void) {
	return games_mame_plugin_type_id;
}


GType games_mame_plugin_register_type (GTypeModule * module) {
	static const GTypeInfo g_define_type_info = { sizeof (GamesMamePluginClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) games_mame_plugin_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GamesMamePlugin), 0, (GInstanceInitFunc) games_mame_plugin_instance_init, NULL };
	static const GInterfaceInfo games_plugin_info = { (GInterfaceInitFunc) games_mame_plugin_games_plugin_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	games_mame_plugin_type_id = g_type_module_register_type (module, G_TYPE_OBJECT, "GamesMamePlugin", &g_define_type_info, 0);
	g_type_module_add_interface (module, games_mame_plugin_type_id, GAMES_TYPE_PLUGIN, &games_plugin_info);
	return games_mame_plugin_type_id;
}


GType register_games_plugin (GTypeModule* module) {
	GType result = 0UL;
	g_return_val_if_fail (module != NULL, 0UL);
	games_mame_game_uri_adapter_register_type (module);
	games_mame_plugin_register_type (module);
	result = GAMES_TYPE_MAME_PLUGIN;
	return result;
}



