/* fingerprint.c generated by valac 0.36.12.13-3ae08, the Vala compiler
 * generated from fingerprint.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 <gio/gio.h>


#define GAMES_TYPE_URI (games_uri_get_type ())
#define GAMES_URI(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_URI, GamesUri))
#define GAMES_URI_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAMES_TYPE_URI, GamesUriClass))
#define GAMES_IS_URI(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_URI))
#define GAMES_IS_URI_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAMES_TYPE_URI))
#define GAMES_URI_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GAMES_TYPE_URI, GamesUriClass))

typedef struct _GamesUri GamesUri;
typedef struct _GamesUriClass GamesUriClass;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_bytes_unref0(var) ((var == NULL) ? NULL : (var = (g_bytes_unref (var), NULL)))

#define GAMES_TYPE_UID (games_uid_get_type ())
#define GAMES_UID(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_UID, GamesUid))
#define GAMES_IS_UID(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_UID))
#define GAMES_UID_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), GAMES_TYPE_UID, GamesUidIface))

typedef struct _GamesUid GamesUid;
typedef struct _GamesUidIface GamesUidIface;

#define GAMES_TYPE_FINGERPRINT_UID (games_fingerprint_uid_get_type ())
#define GAMES_FINGERPRINT_UID(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_FINGERPRINT_UID, GamesFingerprintUid))
#define GAMES_FINGERPRINT_UID_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAMES_TYPE_FINGERPRINT_UID, GamesFingerprintUidClass))
#define GAMES_IS_FINGERPRINT_UID(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_FINGERPRINT_UID))
#define GAMES_IS_FINGERPRINT_UID_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAMES_TYPE_FINGERPRINT_UID))
#define GAMES_FINGERPRINT_UID_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GAMES_TYPE_FINGERPRINT_UID, GamesFingerprintUidClass))

typedef struct _GamesFingerprintUid GamesFingerprintUid;
typedef struct _GamesFingerprintUidClass GamesFingerprintUidClass;
typedef struct _GamesFingerprintUidPrivate GamesFingerprintUidPrivate;
#define _games_uri_unref0(var) ((var == NULL) ? NULL : (var = (games_uri_unref (var), NULL)))

struct _GamesUidIface {
	GTypeInterface parent_iface;
	gchar* (*get_uid) (GamesUid* self, GError** error);
};

struct _GamesFingerprintUid {
	GObject parent_instance;
	GamesFingerprintUidPrivate * priv;
};

struct _GamesFingerprintUidClass {
	GObjectClass parent_class;
};

struct _GamesFingerprintUidPrivate {
	GamesUri* uri;
	gchar* prefix;
	gsize start;
	gsize* length;
	gchar* uid;
};


static gpointer games_fingerprint_uid_parent_class = NULL;
static GamesUidIface * games_fingerprint_uid_games_uid_parent_iface = NULL;

gpointer games_uri_ref (gpointer instance);
void games_uri_unref (gpointer instance);
GParamSpec* games_param_spec_uri (const gchar* name, const gchar* nick, const gchar* blurb, GType object_type, GParamFlags flags);
void games_value_set_uri (GValue* value, gpointer v_object);
void games_value_take_uri (GValue* value, gpointer v_object);
gpointer games_value_get_uri (const GValue* value);
GType games_uri_get_type (void) G_GNUC_CONST;
gchar* games_fingerprint_get_for_file_uri (GamesUri* uri, gsize start, gsize* length, GError** error);
GFile* games_uri_to_file (GamesUri* self);
gchar* games_fingerprint_get_for_file_input_stream (GFileInputStream* file_stream, gsize start, gsize* length, GError** error);
GType games_uid_get_type (void) G_GNUC_CONST;
GType games_fingerprint_uid_get_type (void) G_GNUC_CONST;
#define GAMES_FINGERPRINT_UID_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GAMES_TYPE_FINGERPRINT_UID, GamesFingerprintUidPrivate))
enum  {
	GAMES_FINGERPRINT_UID_0_PROPERTY
};
GamesFingerprintUid* games_fingerprint_uid_new (GamesUri* uri, const gchar* prefix);
GamesFingerprintUid* games_fingerprint_uid_construct (GType object_type, GamesUri* uri, const gchar* prefix);
GamesFingerprintUid* games_fingerprint_uid_new_for_chunk (GamesUri* uri, const gchar* prefix, gsize start, gsize length);
GamesFingerprintUid* games_fingerprint_uid_construct_for_chunk (GType object_type, GamesUri* uri, const gchar* prefix, gsize start, gsize length);
static gsize* _size_t_dup (gsize* self);
static gchar* games_fingerprint_uid_real_get_uid (GamesUid* base, GError** error);
static void games_fingerprint_uid_finalize (GObject * obj);


gchar* games_fingerprint_get_for_file_uri (GamesUri* uri, gsize start, gsize* length, GError** error) {
	gchar* result = NULL;
	GFile* file = NULL;
	GamesUri* _tmp0_;
	GFile* _tmp1_;
	GFileInputStream* istream = NULL;
	GFile* _tmp2_;
	GFileInputStream* _tmp3_;
	gchar* _tmp4_ = NULL;
	GFileInputStream* _tmp5_;
	gsize _tmp6_;
	gsize* _tmp7_;
	gchar* _tmp8_;
	gchar* _tmp9_;
	GError * _inner_error_ = NULL;
	g_return_val_if_fail (uri != NULL, NULL);
	_tmp0_ = uri;
	_tmp1_ = games_uri_to_file (_tmp0_);
	file = _tmp1_;
	_tmp2_ = file;
	_tmp3_ = g_file_read (_tmp2_, NULL, &_inner_error_);
	istream = _tmp3_;
	if (G_UNLIKELY (_inner_error_ != NULL)) {
		g_propagate_error (error, _inner_error_);
		_g_object_unref0 (file);
		return NULL;
	}
	_tmp5_ = istream;
	_tmp6_ = start;
	_tmp7_ = length;
	_tmp8_ = games_fingerprint_get_for_file_input_stream (_tmp5_, _tmp6_, _tmp7_, &_inner_error_);
	_tmp4_ = _tmp8_;
	if (G_UNLIKELY (_inner_error_ != NULL)) {
		g_propagate_error (error, _inner_error_);
		_g_object_unref0 (istream);
		_g_object_unref0 (file);
		return NULL;
	}
	_tmp9_ = _tmp4_;
	_tmp4_ = NULL;
	result = _tmp9_;
	_g_free0 (_tmp4_);
	_g_object_unref0 (istream);
	_g_object_unref0 (file);
	return result;
}


gchar* games_fingerprint_get_for_file_input_stream (GFileInputStream* file_stream, gsize start, gsize* length, GError** error) {
	gchar* result = NULL;
	gsize size = 0UL;
	gsize* _tmp0_;
	GFileInputStream* _tmp5_;
	gsize _tmp6_;
	GBytes* bytes = NULL;
	GFileInputStream* _tmp7_;
	gsize _tmp8_;
	GBytes* _tmp9_;
	GBytes* _tmp10_;
	gchar* _tmp11_;
	GError * _inner_error_ = NULL;
	g_return_val_if_fail (file_stream != NULL, NULL);
	_tmp0_ = length;
	if (_tmp0_ == NULL) {
		GFileInputStream* _tmp1_;
		GFileInputStream* _tmp2_;
		gint64 _tmp3_;
		_tmp1_ = file_stream;
		G_FILE_INPUT_STREAM_GET_CLASS (_tmp1_)->seek (_tmp1_, (gint64) 0, G_SEEK_END, NULL, &_inner_error_);
		if (G_UNLIKELY (_inner_error_ != NULL)) {
			g_propagate_error (error, _inner_error_);
			return NULL;
		}
		_tmp2_ = file_stream;
		_tmp3_ = G_FILE_INPUT_STREAM_GET_CLASS (_tmp2_)->tell (_tmp2_);
		size = (gsize) _tmp3_;
	} else {
		gsize* _tmp4_;
		_tmp4_ = length;
		size = *_tmp4_;
	}
	_tmp5_ = file_stream;
	_tmp6_ = start;
	G_FILE_INPUT_STREAM_GET_CLASS (_tmp5_)->seek (_tmp5_, (gint64) _tmp6_, G_SEEK_SET, NULL, &_inner_error_);
	if (G_UNLIKELY (_inner_error_ != NULL)) {
		g_propagate_error (error, _inner_error_);
		return NULL;
	}
	_tmp7_ = file_stream;
	_tmp8_ = size;
	_tmp9_ = g_input_stream_read_bytes ((GInputStream*) _tmp7_, _tmp8_, NULL, &_inner_error_);
	bytes = _tmp9_;
	if (G_UNLIKELY (_inner_error_ != NULL)) {
		g_propagate_error (error, _inner_error_);
		return NULL;
	}
	_tmp10_ = bytes;
	_tmp11_ = g_compute_checksum_for_bytes (G_CHECKSUM_MD5, _tmp10_);
	result = _tmp11_;
	_g_bytes_unref0 (bytes);
	return result;
}


static gpointer _games_uri_ref0 (gpointer self) {
	return self ? games_uri_ref (self) : NULL;
}


GamesFingerprintUid* games_fingerprint_uid_construct (GType object_type, GamesUri* uri, const gchar* prefix) {
	GamesFingerprintUid * self = NULL;
	GamesUri* _tmp0_;
	GamesUri* _tmp1_;
	const gchar* _tmp2_;
	gchar* _tmp3_;
	g_return_val_if_fail (uri != NULL, NULL);
	g_return_val_if_fail (prefix != NULL, NULL);
	self = (GamesFingerprintUid*) g_object_new (object_type, NULL);
	_tmp0_ = uri;
	_tmp1_ = _games_uri_ref0 (_tmp0_);
	_games_uri_unref0 (self->priv->uri);
	self->priv->uri = _tmp1_;
	_tmp2_ = prefix;
	_tmp3_ = g_strdup (_tmp2_);
	_g_free0 (self->priv->prefix);
	self->priv->prefix = _tmp3_;
	self->priv->start = (gsize) 0;
	_g_free0 (self->priv->length);
	self->priv->length = NULL;
	return self;
}


GamesFingerprintUid* games_fingerprint_uid_new (GamesUri* uri, const gchar* prefix) {
	return games_fingerprint_uid_construct (GAMES_TYPE_FINGERPRINT_UID, uri, prefix);
}


static gsize* _size_t_dup (gsize* self) {
	gsize* dup;
	dup = g_new0 (gsize, 1);
	memcpy (dup, self, sizeof (gsize));
	return dup;
}


static gpointer __size_t_dup0 (gpointer self) {
	return self ? _size_t_dup (self) : NULL;
}


GamesFingerprintUid* games_fingerprint_uid_construct_for_chunk (GType object_type, GamesUri* uri, const gchar* prefix, gsize start, gsize length) {
	GamesFingerprintUid * self = NULL;
	GamesUri* _tmp0_;
	GamesUri* _tmp1_;
	const gchar* _tmp2_;
	gchar* _tmp3_;
	gsize _tmp4_;
	gsize _tmp5_;
	gsize* _tmp6_;
	g_return_val_if_fail (uri != NULL, NULL);
	g_return_val_if_fail (prefix != NULL, NULL);
	self = (GamesFingerprintUid*) g_object_new (object_type, NULL);
	_tmp0_ = uri;
	_tmp1_ = _games_uri_ref0 (_tmp0_);
	_games_uri_unref0 (self->priv->uri);
	self->priv->uri = _tmp1_;
	_tmp2_ = prefix;
	_tmp3_ = g_strdup (_tmp2_);
	_g_free0 (self->priv->prefix);
	self->priv->prefix = _tmp3_;
	_tmp4_ = start;
	self->priv->start = _tmp4_;
	_tmp5_ = length;
	_tmp6_ = __size_t_dup0 (&_tmp5_);
	_g_free0 (self->priv->length);
	self->priv->length = _tmp6_;
	return self;
}


GamesFingerprintUid* games_fingerprint_uid_new_for_chunk (GamesUri* uri, const gchar* prefix, gsize start, gsize length) {
	return games_fingerprint_uid_construct_for_chunk (GAMES_TYPE_FINGERPRINT_UID, uri, prefix, start, length);
}


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_fingerprint_uid_real_get_uid (GamesUid* base, GError** error) {
	GamesFingerprintUid * self;
	gchar* result = NULL;
	const gchar* _tmp0_;
	gchar* fingerprint = NULL;
	GamesUri* _tmp3_;
	gsize _tmp4_;
	gsize* _tmp5_;
	gchar* _tmp6_;
	const gchar* _tmp7_;
	const gchar* _tmp8_;
	const gchar* _tmp9_;
	const gchar* _tmp10_;
	gchar* _tmp11_;
	const gchar* _tmp12_;
	gchar* _tmp13_;
	GError * _inner_error_ = NULL;
	self = (GamesFingerprintUid*) 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->uri;
	_tmp4_ = self->priv->start;
	_tmp5_ = self->priv->length;
	_tmp6_ = games_fingerprint_get_for_file_uri (_tmp3_, _tmp4_, _tmp5_, &_inner_error_);
	fingerprint = _tmp6_;
	if (G_UNLIKELY (_inner_error_ != NULL)) {
		g_propagate_error (error, _inner_error_);
		return NULL;
	}
	_tmp7_ = self->priv->prefix;
	_tmp8_ = string_to_string (_tmp7_);
	_tmp9_ = fingerprint;
	_tmp10_ = string_to_string (_tmp9_);
	_tmp11_ = g_strconcat (_tmp8_, "-", _tmp10_, NULL);
	_g_free0 (self->priv->uid);
	self->priv->uid = _tmp11_;
	_tmp12_ = self->priv->uid;
	_tmp13_ = g_strdup (_tmp12_);
	result = _tmp13_;
	_g_free0 (fingerprint);
	return result;
}


static void games_fingerprint_uid_class_init (GamesFingerprintUidClass * klass) {
	games_fingerprint_uid_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (GamesFingerprintUidPrivate));
	G_OBJECT_CLASS (klass)->finalize = games_fingerprint_uid_finalize;
}


static void games_fingerprint_uid_games_uid_interface_init (GamesUidIface * iface) {
	games_fingerprint_uid_games_uid_parent_iface = g_type_interface_peek_parent (iface);
	iface->get_uid = (gchar* (*) (GamesUid *, GError**)) games_fingerprint_uid_real_get_uid;
}


static void games_fingerprint_uid_instance_init (GamesFingerprintUid * self) {
	self->priv = GAMES_FINGERPRINT_UID_GET_PRIVATE (self);
}


static void games_fingerprint_uid_finalize (GObject * obj) {
	GamesFingerprintUid * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GAMES_TYPE_FINGERPRINT_UID, GamesFingerprintUid);
	_games_uri_unref0 (self->priv->uri);
	_g_free0 (self->priv->prefix);
	_g_free0 (self->priv->length);
	_g_free0 (self->priv->uid);
	G_OBJECT_CLASS (games_fingerprint_uid_parent_class)->finalize (obj);
}


GType games_fingerprint_uid_get_type (void) {
	static volatile gsize games_fingerprint_uid_type_id__volatile = 0;
	if (g_once_init_enter (&games_fingerprint_uid_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (GamesFingerprintUidClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) games_fingerprint_uid_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GamesFingerprintUid), 0, (GInstanceInitFunc) games_fingerprint_uid_instance_init, NULL };
		static const GInterfaceInfo games_uid_info = { (GInterfaceInitFunc) games_fingerprint_uid_games_uid_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
		GType games_fingerprint_uid_type_id;
		games_fingerprint_uid_type_id = g_type_register_static (G_TYPE_OBJECT, "GamesFingerprintUid", &g_define_type_info, 0);
		g_type_add_interface_static (games_fingerprint_uid_type_id, GAMES_TYPE_UID, &games_uid_info);
		g_once_init_leave (&games_fingerprint_uid_type_id__volatile, games_fingerprint_uid_type_id);
	}
	return games_fingerprint_uid_type_id__volatile;
}



