/* gameinfo-doc.c generated by valac 0.36.12.13-3ae08, the Vala compiler
 * generated from gameinfo-doc.vala, do not modify */

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

#include <glib.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <libxml/tree.h>
#include <glib/gi18n-lib.h>


#define GAMES_TYPE_GAMEINFO_DOC (games_gameinfo_doc_get_type ())
#define GAMES_GAMEINFO_DOC(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_GAMEINFO_DOC, GamesGameinfoDoc))
#define GAMES_GAMEINFO_DOC_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAMES_TYPE_GAMEINFO_DOC, GamesGameinfoDocClass))
#define GAMES_IS_GAMEINFO_DOC(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_GAMEINFO_DOC))
#define GAMES_IS_GAMEINFO_DOC_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAMES_TYPE_GAMEINFO_DOC))
#define GAMES_GAMEINFO_DOC_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GAMES_TYPE_GAMEINFO_DOC, GamesGameinfoDocClass))

typedef struct _GamesGameinfoDoc GamesGameinfoDoc;
typedef struct _GamesGameinfoDocClass GamesGameinfoDocClass;
typedef struct _GamesGameinfoDocPrivate GamesGameinfoDocPrivate;

#define GAMES_TYPE_XML_DOC (games_xml_doc_get_type ())
#define GAMES_XML_DOC(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_XML_DOC, GamesXmlDoc))
#define GAMES_XML_DOC_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAMES_TYPE_XML_DOC, GamesXmlDocClass))
#define GAMES_IS_XML_DOC(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_XML_DOC))
#define GAMES_IS_XML_DOC_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAMES_TYPE_XML_DOC))
#define GAMES_XML_DOC_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GAMES_TYPE_XML_DOC, GamesXmlDocClass))

typedef struct _GamesXmlDoc GamesXmlDoc;
typedef struct _GamesXmlDocClass GamesXmlDocClass;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))

struct _GamesGameinfoDoc {
	GObject parent_instance;
	GamesGameinfoDocPrivate * priv;
};

struct _GamesGameinfoDocClass {
	GObjectClass parent_class;
};

struct _GamesGameinfoDocPrivate {
	GamesXmlDoc* xml_doc;
};

typedef enum  {
	GAMES_GAMEINFO_ERROR_DISC_NOT_FOUND
} GamesGameinfoError;
#define GAMES_GAMEINFO_ERROR games_gameinfo_error_quark ()

static gpointer games_gameinfo_doc_parent_class = NULL;

GType games_gameinfo_doc_get_type (void) G_GNUC_CONST;
GType games_xml_doc_get_type (void) G_GNUC_CONST;
#define GAMES_GAMEINFO_DOC_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GAMES_TYPE_GAMEINFO_DOC, GamesGameinfoDocPrivate))
enum  {
	GAMES_GAMEINFO_DOC_0_PROPERTY
};
GamesGameinfoDoc* games_gameinfo_doc_new_from_data (guint8* data, int data_length1, GError** error);
GamesGameinfoDoc* games_gameinfo_doc_construct_from_data (GType object_type, guint8* data, int data_length1, GError** error);
GamesXmlDoc* games_xml_doc_new_from_data (guint8* data, int data_length1, GError** error);
GamesXmlDoc* games_xml_doc_construct_from_data (GType object_type, guint8* data, int data_length1, GError** error);
gchar* games_gameinfo_doc_get_game_title_for_disc_id (GamesGameinfoDoc* self, const gchar* disc_id, GError** error);
gchar* games_xml_doc_get_content (GamesXmlDoc* self, const gchar* xpath, xmlNode* current_node);
GQuark games_gameinfo_error_quark (void);
gchar** games_gameinfo_doc_get_game_controllers_for_disc_id (GamesGameinfoDoc* self, const gchar* disc_id, int* result_length1, GError** error);
gchar** games_xml_doc_get_contents (GamesXmlDoc* self, const gchar* xpath, xmlNode* current_node, int* result_length1);
gchar* games_gameinfo_doc_get_disc_title_for_disc_id (GamesGameinfoDoc* self, const gchar* disc_id, GError** error);
gchar* games_gameinfo_doc_get_disc_set_id_for_disc_id (GamesGameinfoDoc* self, const gchar* disc_id, GError** error);
gint games_gameinfo_doc_get_disc_set_index_for_disc_id (GamesGameinfoDoc* self, const gchar* disc_id, GError** error);
gint games_xml_doc_count_nodes (GamesXmlDoc* self, const gchar* xpath, xmlNode* from_node);
gint games_gameinfo_doc_get_disc_set_size_for_disc_id (GamesGameinfoDoc* self, const gchar* disc_id, GError** error);
gchar** games_gameinfo_doc_get_disc_set_ids_for_disc_id (GamesGameinfoDoc* self, const gchar* disc_id, int* result_length1, GError** error);
GamesGameinfoDoc* games_gameinfo_doc_new (void);
GamesGameinfoDoc* games_gameinfo_doc_construct (GType object_type);
static void games_gameinfo_doc_finalize (GObject * obj);


GamesGameinfoDoc* games_gameinfo_doc_construct_from_data (GType object_type, guint8* data, int data_length1, GError** error) {
	GamesGameinfoDoc * self = NULL;
	GamesXmlDoc* _tmp0_ = NULL;
	guint8* _tmp1_;
	gint _tmp1__length1;
	GamesXmlDoc* _tmp2_;
	GamesXmlDoc* _tmp3_;
	GError * _inner_error_ = NULL;
	self = (GamesGameinfoDoc*) g_object_new (object_type, NULL);
	_tmp1_ = data;
	_tmp1__length1 = data_length1;
	_tmp2_ = games_xml_doc_new_from_data (_tmp1_, _tmp1__length1, &_inner_error_);
	_tmp0_ = _tmp2_;
	if (G_UNLIKELY (_inner_error_ != NULL)) {
		g_propagate_error (error, _inner_error_);
		_g_object_unref0 (self);
		return NULL;
	}
	_tmp3_ = _tmp0_;
	_tmp0_ = NULL;
	_g_object_unref0 (self->priv->xml_doc);
	self->priv->xml_doc = _tmp3_;
	_g_object_unref0 (_tmp0_);
	return self;
}


GamesGameinfoDoc* games_gameinfo_doc_new_from_data (guint8* data, int data_length1, GError** error) {
	return games_gameinfo_doc_construct_from_data (GAMES_TYPE_GAMEINFO_DOC, data, data_length1, error);
}


gchar* games_gameinfo_doc_get_game_title_for_disc_id (GamesGameinfoDoc* self, const gchar* disc_id, GError** error) {
	gchar* result = NULL;
	gchar* expr = NULL;
	const gchar* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	gchar* title = NULL;
	GamesXmlDoc* _tmp5_;
	const gchar* _tmp6_;
	gchar* _tmp7_;
	const gchar* _tmp8_;
	GError * _inner_error_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (disc_id != NULL, NULL);
	_tmp0_ = disc_id;
	_tmp1_ = g_strconcat ("/gameinfo/games/game[discs/disc[@id = \"", _tmp0_, NULL);
	_tmp2_ = _tmp1_;
	_tmp3_ = g_strconcat (_tmp2_, "\"]]/title", NULL);
	_tmp4_ = _tmp3_;
	_g_free0 (_tmp2_);
	expr = _tmp4_;
	_tmp5_ = self->priv->xml_doc;
	_tmp6_ = expr;
	_tmp7_ = games_xml_doc_get_content (_tmp5_, _tmp6_, NULL);
	title = _tmp7_;
	_tmp8_ = title;
	if (_tmp8_ == NULL) {
		const gchar* _tmp9_;
		GError* _tmp10_;
		_tmp9_ = disc_id;
		_tmp10_ = g_error_new (GAMES_GAMEINFO_ERROR, GAMES_GAMEINFO_ERROR_DISC_NOT_FOUND, _ ("No game title found for disc ID “%s”."), _tmp9_);
		_inner_error_ = _tmp10_;
		g_propagate_error (error, _inner_error_);
		_g_free0 (title);
		_g_free0 (expr);
		return NULL;
	}
	result = title;
	_g_free0 (expr);
	return result;
}


gchar** games_gameinfo_doc_get_game_controllers_for_disc_id (GamesGameinfoDoc* self, const gchar* disc_id, int* result_length1, GError** error) {
	gchar** result = NULL;
	gchar* expr = NULL;
	const gchar* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	GamesXmlDoc* _tmp5_;
	gint _tmp6_;
	gchar** _tmp7_;
	gchar** _tmp8_;
	gint _tmp8__length1;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (disc_id != NULL, NULL);
	_tmp0_ = disc_id;
	_tmp1_ = g_strconcat ("/gameinfo/games/game[discs/disc[@id = \"", _tmp0_, NULL);
	_tmp2_ = _tmp1_;
	_tmp3_ = g_strconcat (_tmp2_, "\"]]/controllers/controller/@type", NULL);
	_tmp4_ = _tmp3_;
	_g_free0 (_tmp2_);
	expr = _tmp4_;
	_tmp5_ = self->priv->xml_doc;
	_tmp7_ = games_xml_doc_get_contents (_tmp5_, expr, NULL, &_tmp6_);
	_tmp8_ = _tmp7_;
	_tmp8__length1 = _tmp6_;
	if (result_length1) {
		*result_length1 = _tmp8__length1;
	}
	result = _tmp8_;
	_g_free0 (expr);
	return result;
}


gchar* games_gameinfo_doc_get_disc_title_for_disc_id (GamesGameinfoDoc* self, const gchar* disc_id, GError** error) {
	gchar* result = NULL;
	gchar* expr = NULL;
	const gchar* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	gchar* title = NULL;
	GamesXmlDoc* _tmp5_;
	const gchar* _tmp6_;
	gchar* _tmp7_;
	const gchar* _tmp8_;
	GError * _inner_error_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (disc_id != NULL, NULL);
	_tmp0_ = disc_id;
	_tmp1_ = g_strconcat ("/gameinfo/games/game/discs/disc[@id = \"", _tmp0_, NULL);
	_tmp2_ = _tmp1_;
	_tmp3_ = g_strconcat (_tmp2_, "\"]/title", NULL);
	_tmp4_ = _tmp3_;
	_g_free0 (_tmp2_);
	expr = _tmp4_;
	_tmp5_ = self->priv->xml_doc;
	_tmp6_ = expr;
	_tmp7_ = games_xml_doc_get_content (_tmp5_, _tmp6_, NULL);
	title = _tmp7_;
	_tmp8_ = title;
	if (_tmp8_ == NULL) {
		const gchar* _tmp9_;
		GError* _tmp10_;
		_tmp9_ = disc_id;
		_tmp10_ = g_error_new (GAMES_GAMEINFO_ERROR, GAMES_GAMEINFO_ERROR_DISC_NOT_FOUND, _ ("No disc title found for disc ID “%s”."), _tmp9_);
		_inner_error_ = _tmp10_;
		g_propagate_error (error, _inner_error_);
		_g_free0 (title);
		_g_free0 (expr);
		return NULL;
	}
	result = title;
	_g_free0 (expr);
	return result;
}


gchar* games_gameinfo_doc_get_disc_set_id_for_disc_id (GamesGameinfoDoc* self, const gchar* disc_id, GError** error) {
	gchar* result = NULL;
	gchar* expr = NULL;
	const gchar* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	gchar* title = NULL;
	GamesXmlDoc* _tmp5_;
	const gchar* _tmp6_;
	gchar* _tmp7_;
	const gchar* _tmp8_;
	GError * _inner_error_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (disc_id != NULL, NULL);
	_tmp0_ = disc_id;
	_tmp1_ = g_strconcat ("/gameinfo/games/game/discs[disc[@id = \"", _tmp0_, NULL);
	_tmp2_ = _tmp1_;
	_tmp3_ = g_strconcat (_tmp2_, "\"]]/disc[1]/@id", NULL);
	_tmp4_ = _tmp3_;
	_g_free0 (_tmp2_);
	expr = _tmp4_;
	_tmp5_ = self->priv->xml_doc;
	_tmp6_ = expr;
	_tmp7_ = games_xml_doc_get_content (_tmp5_, _tmp6_, NULL);
	title = _tmp7_;
	_tmp8_ = title;
	if (_tmp8_ == NULL) {
		const gchar* _tmp9_;
		GError* _tmp10_;
		_tmp9_ = disc_id;
		_tmp10_ = g_error_new (GAMES_GAMEINFO_ERROR, GAMES_GAMEINFO_ERROR_DISC_NOT_FOUND, _ ("No disc set ID found for disc ID “%s”."), _tmp9_);
		_inner_error_ = _tmp10_;
		g_propagate_error (error, _inner_error_);
		_g_free0 (title);
		_g_free0 (expr);
		return NULL;
	}
	result = title;
	_g_free0 (expr);
	return result;
}


gint games_gameinfo_doc_get_disc_set_index_for_disc_id (GamesGameinfoDoc* self, const gchar* disc_id, GError** error) {
	gint result = 0;
	gchar* test_expr = NULL;
	const gchar* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	GamesXmlDoc* _tmp5_;
	const gchar* _tmp6_;
	gint _tmp7_;
	gchar* expr = NULL;
	const gchar* _tmp11_;
	gchar* _tmp12_;
	gchar* _tmp13_;
	gchar* _tmp14_;
	gchar* _tmp15_;
	GamesXmlDoc* _tmp16_;
	gint _tmp17_;
	GError * _inner_error_ = NULL;
	g_return_val_if_fail (self != NULL, 0);
	g_return_val_if_fail (disc_id != NULL, 0);
	_tmp0_ = disc_id;
	_tmp1_ = g_strconcat ("/gameinfo/games/game/discs/disc[@id = \"", _tmp0_, NULL);
	_tmp2_ = _tmp1_;
	_tmp3_ = g_strconcat (_tmp2_, "\"]", NULL);
	_tmp4_ = _tmp3_;
	_g_free0 (_tmp2_);
	test_expr = _tmp4_;
	_tmp5_ = self->priv->xml_doc;
	_tmp6_ = test_expr;
	_tmp7_ = games_xml_doc_count_nodes (_tmp5_, _tmp6_, NULL);
	if (_tmp7_ == 0) {
		const gchar* _tmp8_;
		GError* _tmp9_;
		gint _tmp10_ = 0;
		_tmp8_ = disc_id;
		_tmp9_ = g_error_new (GAMES_GAMEINFO_ERROR, GAMES_GAMEINFO_ERROR_DISC_NOT_FOUND, _ ("No disc found for disc ID “%s”."), _tmp8_);
		_inner_error_ = _tmp9_;
		g_propagate_error (error, _inner_error_);
		_g_free0 (test_expr);
		return _tmp10_;
	}
	_tmp11_ = disc_id;
	_tmp12_ = g_strconcat ("/gameinfo/games/game/discs/disc[@id = \"", _tmp11_, NULL);
	_tmp13_ = _tmp12_;
	_tmp14_ = g_strconcat (_tmp13_, "\"]/preceding-sibling::disc", NULL);
	_tmp15_ = _tmp14_;
	_g_free0 (_tmp13_);
	expr = _tmp15_;
	_tmp16_ = self->priv->xml_doc;
	_tmp17_ = games_xml_doc_count_nodes (_tmp16_, expr, NULL);
	result = _tmp17_;
	_g_free0 (expr);
	_g_free0 (test_expr);
	return result;
}


gint games_gameinfo_doc_get_disc_set_size_for_disc_id (GamesGameinfoDoc* self, const gchar* disc_id, GError** error) {
	gint result = 0;
	gchar* test_expr = NULL;
	const gchar* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	GamesXmlDoc* _tmp5_;
	const gchar* _tmp6_;
	gint _tmp7_;
	gchar* expr = NULL;
	const gchar* _tmp11_;
	gchar* _tmp12_;
	gchar* _tmp13_;
	gchar* _tmp14_;
	gchar* _tmp15_;
	GamesXmlDoc* _tmp16_;
	gint _tmp17_;
	GError * _inner_error_ = NULL;
	g_return_val_if_fail (self != NULL, 0);
	g_return_val_if_fail (disc_id != NULL, 0);
	_tmp0_ = disc_id;
	_tmp1_ = g_strconcat ("/gameinfo/games/game/discs/disc[@id = \"", _tmp0_, NULL);
	_tmp2_ = _tmp1_;
	_tmp3_ = g_strconcat (_tmp2_, "\"]", NULL);
	_tmp4_ = _tmp3_;
	_g_free0 (_tmp2_);
	test_expr = _tmp4_;
	_tmp5_ = self->priv->xml_doc;
	_tmp6_ = test_expr;
	_tmp7_ = games_xml_doc_count_nodes (_tmp5_, _tmp6_, NULL);
	if (_tmp7_ == 0) {
		const gchar* _tmp8_;
		GError* _tmp9_;
		gint _tmp10_ = 0;
		_tmp8_ = disc_id;
		_tmp9_ = g_error_new (GAMES_GAMEINFO_ERROR, GAMES_GAMEINFO_ERROR_DISC_NOT_FOUND, _ ("No disc found for disc ID “%s”."), _tmp8_);
		_inner_error_ = _tmp9_;
		g_propagate_error (error, _inner_error_);
		_g_free0 (test_expr);
		return _tmp10_;
	}
	_tmp11_ = disc_id;
	_tmp12_ = g_strconcat ("/gameinfo/games/game/discs[disc[@id = \"", _tmp11_, NULL);
	_tmp13_ = _tmp12_;
	_tmp14_ = g_strconcat (_tmp13_, "\"]]/disc", NULL);
	_tmp15_ = _tmp14_;
	_g_free0 (_tmp13_);
	expr = _tmp15_;
	_tmp16_ = self->priv->xml_doc;
	_tmp17_ = games_xml_doc_count_nodes (_tmp16_, expr, NULL);
	result = _tmp17_;
	_g_free0 (expr);
	_g_free0 (test_expr);
	return result;
}


gchar** games_gameinfo_doc_get_disc_set_ids_for_disc_id (GamesGameinfoDoc* self, const gchar* disc_id, int* result_length1, GError** error) {
	gchar** result = NULL;
	gchar* expr = NULL;
	const gchar* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	GamesXmlDoc* _tmp5_;
	gint _tmp6_;
	gchar** _tmp7_;
	gchar** _tmp8_;
	gint _tmp8__length1;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (disc_id != NULL, NULL);
	_tmp0_ = disc_id;
	_tmp1_ = g_strconcat ("/gameinfo/games/game/discs[disc[@id = \"", _tmp0_, NULL);
	_tmp2_ = _tmp1_;
	_tmp3_ = g_strconcat (_tmp2_, "\"]]/disc/@id", NULL);
	_tmp4_ = _tmp3_;
	_g_free0 (_tmp2_);
	expr = _tmp4_;
	_tmp5_ = self->priv->xml_doc;
	_tmp7_ = games_xml_doc_get_contents (_tmp5_, expr, NULL, &_tmp6_);
	_tmp8_ = _tmp7_;
	_tmp8__length1 = _tmp6_;
	if (result_length1) {
		*result_length1 = _tmp8__length1;
	}
	result = _tmp8_;
	_g_free0 (expr);
	return result;
}


GamesGameinfoDoc* games_gameinfo_doc_construct (GType object_type) {
	GamesGameinfoDoc * self = NULL;
	self = (GamesGameinfoDoc*) g_object_new (object_type, NULL);
	return self;
}


GamesGameinfoDoc* games_gameinfo_doc_new (void) {
	return games_gameinfo_doc_construct (GAMES_TYPE_GAMEINFO_DOC);
}


static void games_gameinfo_doc_class_init (GamesGameinfoDocClass * klass) {
	games_gameinfo_doc_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (GamesGameinfoDocPrivate));
	G_OBJECT_CLASS (klass)->finalize = games_gameinfo_doc_finalize;
}


static void games_gameinfo_doc_instance_init (GamesGameinfoDoc * self) {
	self->priv = GAMES_GAMEINFO_DOC_GET_PRIVATE (self);
}


static void games_gameinfo_doc_finalize (GObject * obj) {
	GamesGameinfoDoc * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GAMES_TYPE_GAMEINFO_DOC, GamesGameinfoDoc);
	_g_object_unref0 (self->priv->xml_doc);
	G_OBJECT_CLASS (games_gameinfo_doc_parent_class)->finalize (obj);
}


GType games_gameinfo_doc_get_type (void) {
	static volatile gsize games_gameinfo_doc_type_id__volatile = 0;
	if (g_once_init_enter (&games_gameinfo_doc_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (GamesGameinfoDocClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) games_gameinfo_doc_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GamesGameinfoDoc), 0, (GInstanceInitFunc) games_gameinfo_doc_instance_init, NULL };
		GType games_gameinfo_doc_type_id;
		games_gameinfo_doc_type_id = g_type_register_static (G_TYPE_OBJECT, "GamesGameinfoDoc", &g_define_type_info, 0);
		g_once_init_leave (&games_gameinfo_doc_type_id__volatile, games_gameinfo_doc_type_id);
	}
	return games_gameinfo_doc_type_id__volatile;
}



