/* simple_spks.c generated by valac 0.56.19, the Vala compiler
 * generated from simple_spks.vala, do not modify */

#include "omemo.h"
#include <gee.h>
#include <glib-object.h>
#include <glib.h>
#include <string.h>

#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif

enum  {
	OMEMO_SIMPLE_SIGNED_PRE_KEY_STORE_0_PROPERTY,
	OMEMO_SIMPLE_SIGNED_PRE_KEY_STORE_NUM_PROPERTIES
};
static GParamSpec* omemo_simple_signed_pre_key_store_properties[OMEMO_SIMPLE_SIGNED_PRE_KEY_STORE_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _omemo_signed_pre_key_store_key_unref0(var) ((var == NULL) ? NULL : (var = (omemo_signed_pre_key_store_key_unref (var), NULL)))

struct _OmemoSimpleSignedPreKeyStorePrivate {
	GeeMap* pre_key_map;
};

static gint OmemoSimpleSignedPreKeyStore_private_offset;
static gpointer omemo_simple_signed_pre_key_store_parent_class = NULL;

static guint8* omemo_simple_signed_pre_key_store_real_load_signed_pre_key (OmemoSignedPreKeyStore* base,
                                                                    guint32 pre_key_id,
                                                                    gint* result_length1,
                                                                    GError** error);
static guint8* _vala_array_dup31 (guint8* self,
                           gssize length);
static void omemo_simple_signed_pre_key_store_real_store_signed_pre_key (OmemoSignedPreKeyStore* base,
                                                                  guint32 pre_key_id,
                                                                  guint8* record,
                                                                  gint record_length1,
                                                                  GError** error);
static gboolean omemo_simple_signed_pre_key_store_real_contains_signed_pre_key (OmemoSignedPreKeyStore* base,
                                                                         guint32 pre_key_id,
                                                                         GError** error);
static void omemo_simple_signed_pre_key_store_real_delete_signed_pre_key (OmemoSignedPreKeyStore* base,
                                                                   guint32 pre_key_id,
                                                                   GError** error);
static void omemo_simple_signed_pre_key_store_finalize (GObject * obj);
static GType omemo_simple_signed_pre_key_store_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
omemo_simple_signed_pre_key_store_get_instance_private (OmemoSimpleSignedPreKeyStore* self)
{
	return G_STRUCT_MEMBER_P (self, OmemoSimpleSignedPreKeyStore_private_offset);
}

static guint8*
_vala_array_dup31 (guint8* self,
                   gssize length)
{
	if (length > 0) {
		return _vala_memdup2 (self, length * sizeof (guint8));
	}
	return NULL;
}

static guint8*
omemo_simple_signed_pre_key_store_real_load_signed_pre_key (OmemoSignedPreKeyStore* base,
                                                            guint32 pre_key_id,
                                                            gint* result_length1,
                                                            GError** error)
{
	OmemoSimpleSignedPreKeyStore * self;
	gboolean _tmp0_ = FALSE;
	guint8* _tmp10_;
	gint _tmp10__length1;
	GError* _inner_error0_ = NULL;
	guint8* result;
	self = (OmemoSimpleSignedPreKeyStore*) base;
	_tmp0_ = omemo_signed_pre_key_store_contains_signed_pre_key ((OmemoSignedPreKeyStore*) self, pre_key_id, &_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		return NULL;
	}
	if (_tmp0_) {
		GeeMap* _tmp1_;
		gpointer _tmp2_;
		OmemoSignedPreKeyStoreKey* _tmp3_;
		guint8* _tmp4_;
		gint _tmp4__length1;
		gint _tmp5_ = 0;
		guint8* _tmp6_;
		gint _tmp6__length1;
		guint8* _tmp7_;
		gint _tmp7__length1;
		guint8* _tmp8_;
		gint _tmp8__length1;
		guint8* _tmp9_;
		gint _tmp9__length1;
		_tmp1_ = self->priv->pre_key_map;
		_tmp2_ = gee_map_get (_tmp1_, (gpointer) ((guintptr) pre_key_id));
		_tmp3_ = (OmemoSignedPreKeyStoreKey*) _tmp2_;
		_tmp4_ = omemo_signed_pre_key_store_key_get_record (_tmp3_, &_tmp5_);
		_tmp4__length1 = _tmp5_;
		_tmp6_ = _tmp4_;
		_tmp6__length1 = _tmp4__length1;
		_tmp7_ = (_tmp6_ != NULL) ? _vala_array_dup31 (_tmp6_, _tmp6__length1) : _tmp6_;
		_tmp7__length1 = _tmp6__length1;
		_tmp8_ = _tmp7_;
		_tmp8__length1 = _tmp7__length1;
		_omemo_signed_pre_key_store_key_unref0 (_tmp3_);
		_tmp9_ = _tmp8_;
		_tmp9__length1 = _tmp8__length1;
		if (result_length1) {
			*result_length1 = _tmp9__length1;
		}
		result = _tmp9_;
		return result;
	}
	_tmp10_ = NULL;
	_tmp10__length1 = 0;
	if (result_length1) {
		*result_length1 = _tmp10__length1;
	}
	result = _tmp10_;
	return result;
}

static void
omemo_simple_signed_pre_key_store_real_store_signed_pre_key (OmemoSignedPreKeyStore* base,
                                                             guint32 pre_key_id,
                                                             guint8* record,
                                                             gint record_length1,
                                                             GError** error)
{
	OmemoSimpleSignedPreKeyStore * self;
	OmemoSignedPreKeyStoreKey* key = NULL;
	OmemoSignedPreKeyStoreKey* _tmp0_;
	GeeMap* _tmp1_;
	self = (OmemoSimpleSignedPreKeyStore*) base;
	_tmp0_ = omemo_signed_pre_key_store_key_new (pre_key_id, record, record_length1);
	key = _tmp0_;
	_tmp1_ = self->priv->pre_key_map;
	gee_map_set (_tmp1_, (gpointer) ((guintptr) pre_key_id), key);
	g_signal_emit_by_name ((OmemoSignedPreKeyStore*) self, "signed-pre-key-stored", key);
	_omemo_signed_pre_key_store_key_unref0 (key);
}

static gboolean
omemo_simple_signed_pre_key_store_real_contains_signed_pre_key (OmemoSignedPreKeyStore* base,
                                                                guint32 pre_key_id,
                                                                GError** error)
{
	OmemoSimpleSignedPreKeyStore * self;
	GeeMap* _tmp0_;
	gboolean result;
	self = (OmemoSimpleSignedPreKeyStore*) base;
	_tmp0_ = self->priv->pre_key_map;
	result = gee_map_has_key (_tmp0_, (gpointer) ((guintptr) pre_key_id));
	return result;
}

static void
omemo_simple_signed_pre_key_store_real_delete_signed_pre_key (OmemoSignedPreKeyStore* base,
                                                              guint32 pre_key_id,
                                                              GError** error)
{
	OmemoSimpleSignedPreKeyStore * self;
	OmemoSignedPreKeyStoreKey* key = NULL;
	GeeMap* _tmp0_;
	gpointer _tmp1_ = NULL;
	gboolean _tmp2_;
	self = (OmemoSimpleSignedPreKeyStore*) base;
	_tmp0_ = self->priv->pre_key_map;
	_tmp2_ = gee_map_unset (_tmp0_, (gpointer) ((guintptr) pre_key_id), &_tmp1_);
	_omemo_signed_pre_key_store_key_unref0 (key);
	key = (OmemoSignedPreKeyStoreKey*) _tmp1_;
	if (_tmp2_) {
		OmemoSignedPreKeyStoreKey* _tmp3_;
		_tmp3_ = key;
		g_signal_emit_by_name ((OmemoSignedPreKeyStore*) self, "signed-pre-key-deleted", _tmp3_);
	}
	_omemo_signed_pre_key_store_key_unref0 (key);
}

OmemoSimpleSignedPreKeyStore*
omemo_simple_signed_pre_key_store_construct (GType object_type)
{
	OmemoSimpleSignedPreKeyStore * self = NULL;
	self = (OmemoSimpleSignedPreKeyStore*) omemo_signed_pre_key_store_construct (object_type);
	return self;
}

OmemoSimpleSignedPreKeyStore*
omemo_simple_signed_pre_key_store_new (void)
{
	return omemo_simple_signed_pre_key_store_construct (OMEMO_TYPE_SIMPLE_SIGNED_PRE_KEY_STORE);
}

static void
omemo_simple_signed_pre_key_store_class_init (OmemoSimpleSignedPreKeyStoreClass * klass,
                                              gpointer klass_data)
{
	omemo_simple_signed_pre_key_store_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &OmemoSimpleSignedPreKeyStore_private_offset);
	((OmemoSignedPreKeyStoreClass *) klass)->load_signed_pre_key = (guint8* (*) (OmemoSignedPreKeyStore*, guint32, gint*, GError**)) omemo_simple_signed_pre_key_store_real_load_signed_pre_key;
	((OmemoSignedPreKeyStoreClass *) klass)->store_signed_pre_key = (void (*) (OmemoSignedPreKeyStore*, guint32, guint8*, gint, GError**)) omemo_simple_signed_pre_key_store_real_store_signed_pre_key;
	((OmemoSignedPreKeyStoreClass *) klass)->contains_signed_pre_key = (gboolean (*) (OmemoSignedPreKeyStore*, guint32, GError**)) omemo_simple_signed_pre_key_store_real_contains_signed_pre_key;
	((OmemoSignedPreKeyStoreClass *) klass)->delete_signed_pre_key = (void (*) (OmemoSignedPreKeyStore*, guint32, GError**)) omemo_simple_signed_pre_key_store_real_delete_signed_pre_key;
	G_OBJECT_CLASS (klass)->finalize = omemo_simple_signed_pre_key_store_finalize;
}

static void
omemo_simple_signed_pre_key_store_instance_init (OmemoSimpleSignedPreKeyStore * self,
                                                 gpointer klass)
{
	GeeHashMap* _tmp0_;
	self->priv = omemo_simple_signed_pre_key_store_get_instance_private (self);
	_tmp0_ = gee_hash_map_new (G_TYPE_UINT, NULL, NULL, OMEMO_SIGNED_PRE_KEY_STORE_TYPE_KEY, (GBoxedCopyFunc) omemo_signed_pre_key_store_key_ref, (GDestroyNotify) omemo_signed_pre_key_store_key_unref, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
	self->priv->pre_key_map = (GeeMap*) _tmp0_;
}

static void
omemo_simple_signed_pre_key_store_finalize (GObject * obj)
{
	OmemoSimpleSignedPreKeyStore * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, OMEMO_TYPE_SIMPLE_SIGNED_PRE_KEY_STORE, OmemoSimpleSignedPreKeyStore);
	_g_object_unref0 (self->priv->pre_key_map);
	G_OBJECT_CLASS (omemo_simple_signed_pre_key_store_parent_class)->finalize (obj);
}

static GType
omemo_simple_signed_pre_key_store_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (OmemoSimpleSignedPreKeyStoreClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) omemo_simple_signed_pre_key_store_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (OmemoSimpleSignedPreKeyStore), 0, (GInstanceInitFunc) omemo_simple_signed_pre_key_store_instance_init, NULL };
	GType omemo_simple_signed_pre_key_store_type_id;
	omemo_simple_signed_pre_key_store_type_id = g_type_register_static (OMEMO_TYPE_SIGNED_PRE_KEY_STORE, "OmemoSimpleSignedPreKeyStore", &g_define_type_info, 0);
	OmemoSimpleSignedPreKeyStore_private_offset = g_type_add_instance_private (omemo_simple_signed_pre_key_store_type_id, sizeof (OmemoSimpleSignedPreKeyStorePrivate));
	return omemo_simple_signed_pre_key_store_type_id;
}

GType
omemo_simple_signed_pre_key_store_get_type (void)
{
	static volatile gsize omemo_simple_signed_pre_key_store_type_id__once = 0;
	if (g_once_init_enter (&omemo_simple_signed_pre_key_store_type_id__once)) {
		GType omemo_simple_signed_pre_key_store_type_id;
		omemo_simple_signed_pre_key_store_type_id = omemo_simple_signed_pre_key_store_get_type_once ();
		g_once_init_leave (&omemo_simple_signed_pre_key_store_type_id__once, omemo_simple_signed_pre_key_store_type_id);
	}
	return omemo_simple_signed_pre_key_store_type_id__once;
}

static inline gpointer
_vala_memdup2 (gconstpointer mem,
               gsize byte_size)
{
	gpointer new_mem;
	if (mem && byte_size != 0) {
		new_mem = g_malloc (byte_size);
		memcpy (new_mem, mem, byte_size);
	} else {
		new_mem = NULL;
	}
	return new_mem;
}

