/* wii-uid.c generated by valac 0.36.6.6-c7bee, the Vala compiler
 * generated from wii-uid.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>


#define GAMES_TYPE_WII_UID (games_wii_uid_get_type ())
#define GAMES_WII_UID(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_WII_UID, GamesWiiUid))
#define GAMES_WII_UID_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAMES_TYPE_WII_UID, GamesWiiUidClass))
#define GAMES_IS_WII_UID(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_WII_UID))
#define GAMES_IS_WII_UID_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAMES_TYPE_WII_UID))
#define GAMES_WII_UID_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GAMES_TYPE_WII_UID, GamesWiiUidClass))

typedef struct _GamesWiiUid GamesWiiUid;
typedef struct _GamesWiiUidClass GamesWiiUidClass;
typedef struct _GamesWiiUidPrivate GamesWiiUidPrivate;

#define GAMES_TYPE_WII_HEADER (games_wii_header_get_type ())
#define GAMES_WII_HEADER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_WII_HEADER, GamesWiiHeader))
#define GAMES_WII_HEADER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAMES_TYPE_WII_HEADER, GamesWiiHeaderClass))
#define GAMES_IS_WII_HEADER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_WII_HEADER))
#define GAMES_IS_WII_HEADER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAMES_TYPE_WII_HEADER))
#define GAMES_WII_HEADER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GAMES_TYPE_WII_HEADER, GamesWiiHeaderClass))

typedef struct _GamesWiiHeader GamesWiiHeader;
typedef struct _GamesWiiHeaderClass GamesWiiHeaderClass;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))

struct _GamesWiiUid {
	GObject parent_instance;
	GamesWiiUidPrivate * priv;
};

struct _GamesWiiUidClass {
	GObjectClass parent_class;
};

struct _GamesWiiUidPrivate {
	GamesWiiHeader* header;
	gchar* uid;
};

typedef enum  {
	GAMES_WII_ERROR_CANT_READ_FILE,
	GAMES_WII_ERROR_INVALID_SIZE,
	GAMES_WII_ERROR_INVALID_HEADER
} GamesWiiError;
#define GAMES_WII_ERROR games_wii_error_quark ()

static gpointer games_wii_uid_parent_class = NULL;
static GamesUidIface * games_wii_uid_games_uid_parent_iface = NULL;
static GType games_wii_uid_type_id = 0;

GType games_wii_uid_get_type (void) G_GNUC_CONST;
GType games_wii_header_get_type (void) G_GNUC_CONST;
#define GAMES_WII_UID_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GAMES_TYPE_WII_UID, GamesWiiUidPrivate))
enum  {
	GAMES_WII_UID_0_PROPERTY
};
GamesWiiUid* games_wii_uid_new (GamesWiiHeader* header);
GamesWiiUid* games_wii_uid_construct (GType object_type, GamesWiiHeader* header);
static gchar* games_wii_uid_real_get_uid (GamesUid* base, GError** error);
GQuark games_wii_error_quark (void);
gchar* games_wii_header_get_game_id (GamesWiiHeader* self, GError** error);
static void games_wii_uid_finalize (GObject * obj);


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


GamesWiiUid* games_wii_uid_construct (GType object_type, GamesWiiHeader* header) {
	GamesWiiUid * self = NULL;
	GamesWiiHeader* _tmp0_;
	GamesWiiHeader* _tmp1_;
	g_return_val_if_fail (header != NULL, NULL);
	self = (GamesWiiUid*) g_object_new (object_type, NULL);
	_tmp0_ = header;
	_tmp1_ = _g_object_ref0 (_tmp0_);
	_g_object_unref0 (self->priv->header);
	self->priv->header = _tmp1_;
	return self;
}


GamesWiiUid* games_wii_uid_new (GamesWiiHeader* header) {
	return games_wii_uid_construct (GAMES_TYPE_WII_UID, header);
}


static const gchar* string_to_string (const gchar* self) {
	const gchar* result = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	result = self;
	return result;
}


static gchar* games_wii_uid_real_get_uid (GamesUid* base, GError** error) {
	GamesWiiUid * self;
	gchar* result = NULL;
	const gchar* _tmp0_;
	gchar* game_id = NULL;
	GamesWiiHeader* _tmp3_;
	gchar* _tmp4_;
	const gchar* _tmp5_;
	const gchar* _tmp6_;
	gchar* _tmp7_;
	gchar* _tmp8_;
	gchar* _tmp9_;
	const gchar* _tmp10_;
	gchar* _tmp11_;
	GError * _inner_error_ = NULL;
	self = (GamesWiiUid*) base;
	_tmp0_ = self->priv->uid;
	if (_tmp0_ != NULL) {
		const gchar* _tmp1_;
		gchar* _tmp2_;
		_tmp1_ = self->priv->uid;
		_tmp2_ = g_strdup (_tmp1_);
		result = _tmp2_;
		return result;
	}
	_tmp3_ = self->priv->header;
	_tmp4_ = games_wii_header_get_game_id (_tmp3_, &_inner_error_);
	game_id = _tmp4_;
	if (G_UNLIKELY (_inner_error_ != NULL)) {
		g_propagate_error (error, _inner_error_);
		return NULL;
	}
	_tmp5_ = game_id;
	_tmp6_ = string_to_string (_tmp5_);
	_tmp7_ = g_strconcat ("wii-", _tmp6_, NULL);
	_tmp8_ = _tmp7_;
	_tmp9_ = g_utf8_strdown (_tmp8_, (gssize) -1);
	_g_free0 (self->priv->uid);
	self->priv->uid = _tmp9_;
	_g_free0 (_tmp8_);
	_tmp10_ = self->priv->uid;
	_tmp11_ = g_strdup (_tmp10_);
	result = _tmp11_;
	_g_free0 (game_id);
	return result;
}


static void games_wii_uid_class_init (GamesWiiUidClass * klass) {
	games_wii_uid_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (GamesWiiUidPrivate));
	G_OBJECT_CLASS (klass)->finalize = games_wii_uid_finalize;
}


static void games_wii_uid_games_uid_interface_init (GamesUidIface * iface) {
	games_wii_uid_games_uid_parent_iface = g_type_interface_peek_parent (iface);
	iface->get_uid = (gchar* (*) (GamesUid *, GError**)) games_wii_uid_real_get_uid;
}


static void games_wii_uid_instance_init (GamesWiiUid * self) {
	self->priv = GAMES_WII_UID_GET_PRIVATE (self);
}


static void games_wii_uid_finalize (GObject * obj) {
	GamesWiiUid * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GAMES_TYPE_WII_UID, GamesWiiUid);
	_g_object_unref0 (self->priv->header);
	_g_free0 (self->priv->uid);
	G_OBJECT_CLASS (games_wii_uid_parent_class)->finalize (obj);
}


GType games_wii_uid_get_type (void) {
	return games_wii_uid_type_id;
}


GType games_wii_uid_register_type (GTypeModule * module) {
	static const GTypeInfo g_define_type_info = { sizeof (GamesWiiUidClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) games_wii_uid_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GamesWiiUid), 0, (GInstanceInitFunc) games_wii_uid_instance_init, NULL };
	static const GInterfaceInfo games_uid_info = { (GInterfaceInitFunc) games_wii_uid_games_uid_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	games_wii_uid_type_id = g_type_module_register_type (module, G_TYPE_OBJECT, "GamesWiiUid", &g_define_type_info, 0);
	g_type_module_add_interface (module, games_wii_uid_type_id, GAMES_TYPE_UID, &games_uid_info);
	return games_wii_uid_type_id;
}



