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

#include "xmpp-vala.h"
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <gio/gio.h>
#include <glib-object.h>
#include <gee.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  {
	XMPP_STANZA_LISTENER_0_PROPERTY,
	XMPP_STANZA_LISTENER_T_TYPE,
	XMPP_STANZA_LISTENER_T_DUP_FUNC,
	XMPP_STANZA_LISTENER_T_DESTROY_FUNC,
	XMPP_STANZA_LISTENER_NUM_PROPERTIES
};
static GParamSpec* xmpp_stanza_listener_properties[XMPP_STANZA_LISTENER_NUM_PROPERTIES];
enum  {
	XMPP_STANZA_LISTENER_HOLDER_0_PROPERTY,
	XMPP_STANZA_LISTENER_HOLDER_T_TYPE,
	XMPP_STANZA_LISTENER_HOLDER_T_DUP_FUNC,
	XMPP_STANZA_LISTENER_HOLDER_T_DESTROY_FUNC,
	XMPP_STANZA_LISTENER_HOLDER_NUM_PROPERTIES
};
static GParamSpec* xmpp_stanza_listener_holder_properties[XMPP_STANZA_LISTENER_HOLDER_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef struct _XmppStanzaListenerHolderRunData XmppStanzaListenerHolderRunData;
enum  {
	XMPP_ORDERED_LISTENER_0_PROPERTY,
	XMPP_ORDERED_LISTENER_ACTION_GROUP_PROPERTY,
	XMPP_ORDERED_LISTENER_AFTER_ACTIONS_PROPERTY,
	XMPP_ORDERED_LISTENER_NUM_PROPERTIES
};
static GParamSpec* xmpp_ordered_listener_properties[XMPP_ORDERED_LISTENER_NUM_PROPERTIES];
enum  {
	XMPP_LISTENER_HOLDER_0_PROPERTY,
	XMPP_LISTENER_HOLDER_NUM_PROPERTIES
};
static GParamSpec* xmpp_listener_holder_properties[XMPP_LISTENER_HOLDER_NUM_PROPERTIES];

struct _XmppStanzaListenerPrivate {
	GType t_type;
	GBoxedCopyFunc t_dup_func;
	GDestroyNotify t_destroy_func;
};

struct _XmppStanzaListenerHolderPrivate {
	GType t_type;
	GBoxedCopyFunc t_dup_func;
	GDestroyNotify t_destroy_func;
};

struct _XmppStanzaListenerHolderRunData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	XmppStanzaListenerHolder* self;
	XmppXmppStream* stream;
	gpointer stanza;
	gboolean result;
	GeeArrayList* listeners_copy;
	GeeArrayList* _tmp0_;
	GeeArrayList* _tmp1_;
	GeeArrayList* _tmp2_;
	GeeArrayList* _ol_list;
	GeeArrayList* _tmp3_;
	gint _ol_size;
	GeeArrayList* _tmp4_;
	gint _tmp5_;
	gint _tmp6_;
	gint _ol_index;
	gint _tmp7_;
	gint _tmp8_;
	XmppOrderedListener* ol;
	GeeArrayList* _tmp9_;
	gpointer _tmp10_;
	XmppStanzaListener* l;
	XmppOrderedListener* _tmp11_;
	XmppStanzaListener* _tmp12_;
	gboolean stop;
	XmppStanzaListener* _tmp13_;
};

static gint XmppStanzaListener_private_offset;
static gpointer xmpp_stanza_listener_parent_class = NULL;
static gint XmppStanzaListenerHolder_private_offset;
static gpointer xmpp_stanza_listener_holder_parent_class = NULL;
static gpointer xmpp_ordered_listener_parent_class = NULL;
static gpointer xmpp_listener_holder_parent_class = NULL;

static GType xmpp_stanza_listener_get_type_once (void);
static void _vala_xmpp_stanza_listener_get_property (GObject * object,
                                              guint property_id,
                                              GValue * value,
                                              GParamSpec * pspec);
static void _vala_xmpp_stanza_listener_set_property (GObject * object,
                                              guint property_id,
                                              const GValue * value,
                                              GParamSpec * pspec);
static void xmpp_stanza_listener_holder_run_data_free (gpointer _data);
static gboolean xmpp_stanza_listener_holder_run_co (XmppStanzaListenerHolderRunData* _data_);
static void xmpp_stanza_listener_holder_run_ready (GObject* source_object,
                                            GAsyncResult* _res_,
                                            gpointer _user_data_);
static GType xmpp_stanza_listener_holder_get_type_once (void);
static void _vala_xmpp_stanza_listener_holder_get_property (GObject * object,
                                                     guint property_id,
                                                     GValue * value,
                                                     GParamSpec * pspec);
static void _vala_xmpp_stanza_listener_holder_set_property (GObject * object,
                                                     guint property_id,
                                                     const GValue * value,
                                                     GParamSpec * pspec);
static GType xmpp_ordered_listener_get_type_once (void);
static void _vala_xmpp_ordered_listener_get_property (GObject * object,
                                               guint property_id,
                                               GValue * value,
                                               GParamSpec * pspec);
static void xmpp_listener_holder_resort_list (XmppListenerHolder* self);
static gboolean xmpp_listener_holder_set_contains_action (XmppListenerHolder* self,
                                                   GeeList* s,
                                                   gchar** actions,
                                                   gint actions_length1);
static gboolean _vala_string_array_contains (gchar* * stack,
                                      gssize stack_length,
                                      const gchar* needle);
static void xmpp_listener_holder_finalize (GObject * obj);
static GType xmpp_listener_holder_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

gchar*
xmpp_random_uuid (void)
{
	guint32 b1 = 0U;
	guint16 b2 = 0U;
	guint16 b3 = 0U;
	guint16 b4 = 0U;
	guint16 b5_1 = 0U;
	guint32 b5_2 = 0U;
	gchar* _tmp0_;
	gchar* result;
	b1 = g_random_int ();
	b2 = (guint16) g_random_int ();
	b3 = ((guint16) (g_random_int () | 0x4000U)) & (~0xb000U);
	b4 = ((guint16) (g_random_int () | 0x8000U)) & (~0x4000U);
	b5_1 = (guint16) g_random_int ();
	b5_2 = g_random_int ();
	_tmp0_ = g_strdup_printf ("%08x-%04x-%04x-%04x-%04x%08x", (guint) b1, (guint) b2, (guint) b3, (guint) b4, (guint) b5_1, (guint) b5_2);
	result = _tmp0_;
	return result;
}

static inline gpointer
xmpp_stanza_listener_get_instance_private (XmppStanzaListener* self)
{
	return G_STRUCT_MEMBER_P (self, XmppStanzaListener_private_offset);
}

void
xmpp_stanza_listener_run (XmppStanzaListener* self,
                          XmppXmppStream* stream,
                          gconstpointer stanza,
                          GAsyncReadyCallback _callback_,
                          gpointer _user_data_)
{
	XmppStanzaListenerClass* _klass_;
	_klass_ = XMPP_STANZA_LISTENER_GET_CLASS (self);
	if (_klass_->run) {
		_klass_->run (self, stream, stanza, _callback_, _user_data_);
	}
}

gboolean
xmpp_stanza_listener_run_finish (XmppStanzaListener* self,
                                 GAsyncResult* _res_)
{
	XmppStanzaListenerClass* _klass_;
	_klass_ = XMPP_STANZA_LISTENER_GET_CLASS (self);
	if (_klass_->run_finish) {
		return _klass_->run_finish (self, _res_);
	}
	return FALSE;
}

XmppStanzaListener*
xmpp_stanza_listener_construct (GType object_type,
                                GType t_type,
                                GBoxedCopyFunc t_dup_func,
                                GDestroyNotify t_destroy_func)
{
	XmppStanzaListener * self = NULL;
	self = (XmppStanzaListener*) xmpp_ordered_listener_construct (object_type);
	self->priv->t_type = t_type;
	self->priv->t_dup_func = t_dup_func;
	self->priv->t_destroy_func = t_destroy_func;
	return self;
}

static void
xmpp_stanza_listener_class_init (XmppStanzaListenerClass * klass,
                                 gpointer klass_data)
{
	xmpp_stanza_listener_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &XmppStanzaListener_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_xmpp_stanza_listener_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_xmpp_stanza_listener_set_property;
	g_object_class_install_property (G_OBJECT_CLASS (klass), XMPP_STANZA_LISTENER_T_TYPE, g_param_spec_gtype ("t-type", "type", "type", G_TYPE_NONE, G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
	g_object_class_install_property (G_OBJECT_CLASS (klass), XMPP_STANZA_LISTENER_T_DUP_FUNC, g_param_spec_pointer ("t-dup-func", "dup func", "dup func", G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
	g_object_class_install_property (G_OBJECT_CLASS (klass), XMPP_STANZA_LISTENER_T_DESTROY_FUNC, g_param_spec_pointer ("t-destroy-func", "destroy func", "destroy func", G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
}

static void
xmpp_stanza_listener_instance_init (XmppStanzaListener * self,
                                    gpointer klass)
{
	self->priv = xmpp_stanza_listener_get_instance_private (self);
}

static GType
xmpp_stanza_listener_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (XmppStanzaListenerClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) xmpp_stanza_listener_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (XmppStanzaListener), 0, (GInstanceInitFunc) xmpp_stanza_listener_instance_init, NULL };
	GType xmpp_stanza_listener_type_id;
	xmpp_stanza_listener_type_id = g_type_register_static (XMPP_TYPE_ORDERED_LISTENER, "XmppStanzaListener", &g_define_type_info, G_TYPE_FLAG_ABSTRACT);
	XmppStanzaListener_private_offset = g_type_add_instance_private (xmpp_stanza_listener_type_id, sizeof (XmppStanzaListenerPrivate));
	return xmpp_stanza_listener_type_id;
}

GType
xmpp_stanza_listener_get_type (void)
{
	static volatile gsize xmpp_stanza_listener_type_id__once = 0;
	if (g_once_init_enter (&xmpp_stanza_listener_type_id__once)) {
		GType xmpp_stanza_listener_type_id;
		xmpp_stanza_listener_type_id = xmpp_stanza_listener_get_type_once ();
		g_once_init_leave (&xmpp_stanza_listener_type_id__once, xmpp_stanza_listener_type_id);
	}
	return xmpp_stanza_listener_type_id__once;
}

static void
_vala_xmpp_stanza_listener_get_property (GObject * object,
                                         guint property_id,
                                         GValue * value,
                                         GParamSpec * pspec)
{
	XmppStanzaListener * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, XMPP_TYPE_STANZA_LISTENER, XmppStanzaListener);
	switch (property_id) {
		case XMPP_STANZA_LISTENER_T_TYPE:
		g_value_set_gtype (value, self->priv->t_type);
		break;
		case XMPP_STANZA_LISTENER_T_DUP_FUNC:
		g_value_set_pointer (value, self->priv->t_dup_func);
		break;
		case XMPP_STANZA_LISTENER_T_DESTROY_FUNC:
		g_value_set_pointer (value, self->priv->t_destroy_func);
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_xmpp_stanza_listener_set_property (GObject * object,
                                         guint property_id,
                                         const GValue * value,
                                         GParamSpec * pspec)
{
	XmppStanzaListener * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, XMPP_TYPE_STANZA_LISTENER, XmppStanzaListener);
	switch (property_id) {
		case XMPP_STANZA_LISTENER_T_TYPE:
		self->priv->t_type = g_value_get_gtype (value);
		break;
		case XMPP_STANZA_LISTENER_T_DUP_FUNC:
		self->priv->t_dup_func = g_value_get_pointer (value);
		break;
		case XMPP_STANZA_LISTENER_T_DESTROY_FUNC:
		self->priv->t_destroy_func = g_value_get_pointer (value);
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static inline gpointer
xmpp_stanza_listener_holder_get_instance_private (XmppStanzaListenerHolder* self)
{
	return G_STRUCT_MEMBER_P (self, XmppStanzaListenerHolder_private_offset);
}

static void
xmpp_stanza_listener_holder_run_data_free (gpointer _data)
{
	XmppStanzaListenerHolderRunData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->stream);
	((_data_->stanza == NULL) || (_data_->self->priv->t_destroy_func == NULL)) ? NULL : (_data_->stanza = (_data_->self->priv->t_destroy_func (_data_->stanza), NULL));
	_g_object_unref0 (_data_->self);
	g_slice_free (XmppStanzaListenerHolderRunData, _data_);
}

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

void
xmpp_stanza_listener_holder_run (XmppStanzaListenerHolder* self,
                                 XmppXmppStream* stream,
                                 gconstpointer stanza,
                                 GAsyncReadyCallback _callback_,
                                 gpointer _user_data_)
{
	XmppStanzaListenerHolderRunData* _data_;
	XmppStanzaListenerHolder* _tmp0_;
	XmppXmppStream* _tmp1_;
	gpointer _tmp2_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (stream != NULL);
	_data_ = g_slice_new0 (XmppStanzaListenerHolderRunData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, xmpp_stanza_listener_holder_run_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (stream);
	_g_object_unref0 (_data_->stream);
	_data_->stream = _tmp1_;
	_tmp2_ = ((stanza != NULL) && (self->priv->t_dup_func != NULL)) ? self->priv->t_dup_func ((gpointer) stanza) : ((gpointer) stanza);
	((_data_->stanza == NULL) || (_data_->self->priv->t_destroy_func == NULL)) ? NULL : (_data_->stanza = (_data_->self->priv->t_destroy_func (_data_->stanza), NULL));
	_data_->stanza = _tmp2_;
	xmpp_stanza_listener_holder_run_co (_data_);
}

gboolean
xmpp_stanza_listener_holder_run_finish (XmppStanzaListenerHolder* self,
                                        GAsyncResult* _res_)
{
	gboolean result;
	XmppStanzaListenerHolderRunData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
	result = _data_->result;
	return result;
}

static void
xmpp_stanza_listener_holder_run_ready (GObject* source_object,
                                       GAsyncResult* _res_,
                                       gpointer _user_data_)
{
	XmppStanzaListenerHolderRunData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	xmpp_stanza_listener_holder_run_co (_data_);
}

static gboolean
xmpp_stanza_listener_holder_run_co (XmppStanzaListenerHolderRunData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = gee_array_list_new (XMPP_TYPE_ORDERED_LISTENER, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
	_data_->listeners_copy = _data_->_tmp0_;
	_data_->_tmp1_ = _data_->listeners_copy;
	_data_->_tmp2_ = ((XmppListenerHolder*) _data_->self)->listeners;
	gee_array_list_add_all (_data_->_tmp1_, (GeeCollection*) _data_->_tmp2_);
	{
		_data_->_tmp3_ = _data_->listeners_copy;
		_data_->_ol_list = _data_->_tmp3_;
		_data_->_tmp4_ = _data_->_ol_list;
		_data_->_tmp5_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _data_->_tmp4_);
		_data_->_tmp6_ = _data_->_tmp5_;
		_data_->_ol_size = _data_->_tmp6_;
		_data_->_ol_index = -1;
		while (TRUE) {
			_data_->_ol_index = _data_->_ol_index + 1;
			_data_->_tmp7_ = _data_->_ol_index;
			_data_->_tmp8_ = _data_->_ol_size;
			if (!(_data_->_tmp7_ < _data_->_tmp8_)) {
				break;
			}
			_data_->_tmp9_ = _data_->_ol_list;
			_data_->_tmp10_ = gee_abstract_list_get ((GeeAbstractList*) _data_->_tmp9_, _data_->_ol_index);
			_data_->ol = (XmppOrderedListener*) _data_->_tmp10_;
			_data_->_tmp11_ = _data_->ol;
			_data_->_tmp12_ = _g_object_ref0 (XMPP_IS_STANZA_LISTENER (_data_->_tmp11_) ? ((XmppStanzaListener*) _data_->_tmp11_) : NULL);
			_data_->l = _data_->_tmp12_;
			_data_->_tmp13_ = _data_->l;
			_data_->_state_ = 1;
			xmpp_stanza_listener_run (_data_->_tmp13_, _data_->stream, _data_->stanza, xmpp_stanza_listener_holder_run_ready, _data_);
			return FALSE;
			_state_1:
			_data_->stop = xmpp_stanza_listener_run_finish (_data_->_tmp13_, _data_->_res_);
			if (_data_->stop) {
				_data_->result = TRUE;
				_g_object_unref0 (_data_->l);
				_g_object_unref0 (_data_->ol);
				_g_object_unref0 (_data_->listeners_copy);
				g_task_return_pointer (_data_->_async_result, _data_, NULL);
				if (_data_->_state_ != 0) {
					while (!g_task_get_completed (_data_->_async_result)) {
						g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
					}
				}
				g_object_unref (_data_->_async_result);
				return FALSE;
			}
			_g_object_unref0 (_data_->l);
			_g_object_unref0 (_data_->ol);
		}
	}
	_data_->result = FALSE;
	_g_object_unref0 (_data_->listeners_copy);
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

XmppStanzaListenerHolder*
xmpp_stanza_listener_holder_construct (GType object_type,
                                       GType t_type,
                                       GBoxedCopyFunc t_dup_func,
                                       GDestroyNotify t_destroy_func)
{
	XmppStanzaListenerHolder * self = NULL;
	self = (XmppStanzaListenerHolder*) xmpp_listener_holder_construct (object_type);
	self->priv->t_type = t_type;
	self->priv->t_dup_func = t_dup_func;
	self->priv->t_destroy_func = t_destroy_func;
	return self;
}

XmppStanzaListenerHolder*
xmpp_stanza_listener_holder_new (GType t_type,
                                 GBoxedCopyFunc t_dup_func,
                                 GDestroyNotify t_destroy_func)
{
	return xmpp_stanza_listener_holder_construct (XMPP_TYPE_STANZA_LISTENER_HOLDER, t_type, t_dup_func, t_destroy_func);
}

static void
xmpp_stanza_listener_holder_class_init (XmppStanzaListenerHolderClass * klass,
                                        gpointer klass_data)
{
	xmpp_stanza_listener_holder_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &XmppStanzaListenerHolder_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_xmpp_stanza_listener_holder_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_xmpp_stanza_listener_holder_set_property;
	g_object_class_install_property (G_OBJECT_CLASS (klass), XMPP_STANZA_LISTENER_HOLDER_T_TYPE, g_param_spec_gtype ("t-type", "type", "type", G_TYPE_NONE, G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
	g_object_class_install_property (G_OBJECT_CLASS (klass), XMPP_STANZA_LISTENER_HOLDER_T_DUP_FUNC, g_param_spec_pointer ("t-dup-func", "dup func", "dup func", G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
	g_object_class_install_property (G_OBJECT_CLASS (klass), XMPP_STANZA_LISTENER_HOLDER_T_DESTROY_FUNC, g_param_spec_pointer ("t-destroy-func", "destroy func", "destroy func", G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
}

static void
xmpp_stanza_listener_holder_instance_init (XmppStanzaListenerHolder * self,
                                           gpointer klass)
{
	self->priv = xmpp_stanza_listener_holder_get_instance_private (self);
}

static GType
xmpp_stanza_listener_holder_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (XmppStanzaListenerHolderClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) xmpp_stanza_listener_holder_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (XmppStanzaListenerHolder), 0, (GInstanceInitFunc) xmpp_stanza_listener_holder_instance_init, NULL };
	GType xmpp_stanza_listener_holder_type_id;
	xmpp_stanza_listener_holder_type_id = g_type_register_static (XMPP_TYPE_LISTENER_HOLDER, "XmppStanzaListenerHolder", &g_define_type_info, 0);
	XmppStanzaListenerHolder_private_offset = g_type_add_instance_private (xmpp_stanza_listener_holder_type_id, sizeof (XmppStanzaListenerHolderPrivate));
	return xmpp_stanza_listener_holder_type_id;
}

GType
xmpp_stanza_listener_holder_get_type (void)
{
	static volatile gsize xmpp_stanza_listener_holder_type_id__once = 0;
	if (g_once_init_enter (&xmpp_stanza_listener_holder_type_id__once)) {
		GType xmpp_stanza_listener_holder_type_id;
		xmpp_stanza_listener_holder_type_id = xmpp_stanza_listener_holder_get_type_once ();
		g_once_init_leave (&xmpp_stanza_listener_holder_type_id__once, xmpp_stanza_listener_holder_type_id);
	}
	return xmpp_stanza_listener_holder_type_id__once;
}

static void
_vala_xmpp_stanza_listener_holder_get_property (GObject * object,
                                                guint property_id,
                                                GValue * value,
                                                GParamSpec * pspec)
{
	XmppStanzaListenerHolder * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, XMPP_TYPE_STANZA_LISTENER_HOLDER, XmppStanzaListenerHolder);
	switch (property_id) {
		case XMPP_STANZA_LISTENER_HOLDER_T_TYPE:
		g_value_set_gtype (value, self->priv->t_type);
		break;
		case XMPP_STANZA_LISTENER_HOLDER_T_DUP_FUNC:
		g_value_set_pointer (value, self->priv->t_dup_func);
		break;
		case XMPP_STANZA_LISTENER_HOLDER_T_DESTROY_FUNC:
		g_value_set_pointer (value, self->priv->t_destroy_func);
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_xmpp_stanza_listener_holder_set_property (GObject * object,
                                                guint property_id,
                                                const GValue * value,
                                                GParamSpec * pspec)
{
	XmppStanzaListenerHolder * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, XMPP_TYPE_STANZA_LISTENER_HOLDER, XmppStanzaListenerHolder);
	switch (property_id) {
		case XMPP_STANZA_LISTENER_HOLDER_T_TYPE:
		self->priv->t_type = g_value_get_gtype (value);
		break;
		case XMPP_STANZA_LISTENER_HOLDER_T_DUP_FUNC:
		self->priv->t_dup_func = g_value_get_pointer (value);
		break;
		case XMPP_STANZA_LISTENER_HOLDER_T_DESTROY_FUNC:
		self->priv->t_destroy_func = g_value_get_pointer (value);
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

XmppOrderedListener*
xmpp_ordered_listener_construct (GType object_type)
{
	XmppOrderedListener * self = NULL;
	self = (XmppOrderedListener*) g_object_new (object_type, NULL);
	return self;
}

const gchar*
xmpp_ordered_listener_get_action_group (XmppOrderedListener* self)
{
	XmppOrderedListenerClass* _klass_;
	g_return_val_if_fail (self != NULL, NULL);
	_klass_ = XMPP_ORDERED_LISTENER_GET_CLASS (self);
	if (_klass_->get_action_group) {
		return _klass_->get_action_group (self);
	}
	return NULL;
}

gchar**
xmpp_ordered_listener_get_after_actions (XmppOrderedListener* self,
                                         gint* result_length1)
{
	XmppOrderedListenerClass* _klass_;
	g_return_val_if_fail (self != NULL, NULL);
	_klass_ = XMPP_ORDERED_LISTENER_GET_CLASS (self);
	if (_klass_->get_after_actions) {
		return _klass_->get_after_actions (self, result_length1);
	}
	return NULL;
}

static void
xmpp_ordered_listener_class_init (XmppOrderedListenerClass * klass,
                                  gpointer klass_data)
{
	xmpp_ordered_listener_parent_class = g_type_class_peek_parent (klass);
	G_OBJECT_CLASS (klass)->get_property = _vala_xmpp_ordered_listener_get_property;
	g_object_class_install_property (G_OBJECT_CLASS (klass), XMPP_ORDERED_LISTENER_ACTION_GROUP_PROPERTY, xmpp_ordered_listener_properties[XMPP_ORDERED_LISTENER_ACTION_GROUP_PROPERTY] = g_param_spec_string ("action-group", "action-group", "action-group", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), XMPP_ORDERED_LISTENER_AFTER_ACTIONS_PROPERTY, xmpp_ordered_listener_properties[XMPP_ORDERED_LISTENER_AFTER_ACTIONS_PROPERTY] = g_param_spec_boxed ("after-actions", "after-actions", "after-actions", G_TYPE_STRV, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
}

static void
xmpp_ordered_listener_instance_init (XmppOrderedListener * self,
                                     gpointer klass)
{
}

static GType
xmpp_ordered_listener_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (XmppOrderedListenerClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) xmpp_ordered_listener_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (XmppOrderedListener), 0, (GInstanceInitFunc) xmpp_ordered_listener_instance_init, NULL };
	GType xmpp_ordered_listener_type_id;
	xmpp_ordered_listener_type_id = g_type_register_static (G_TYPE_OBJECT, "XmppOrderedListener", &g_define_type_info, G_TYPE_FLAG_ABSTRACT);
	return xmpp_ordered_listener_type_id;
}

GType
xmpp_ordered_listener_get_type (void)
{
	static volatile gsize xmpp_ordered_listener_type_id__once = 0;
	if (g_once_init_enter (&xmpp_ordered_listener_type_id__once)) {
		GType xmpp_ordered_listener_type_id;
		xmpp_ordered_listener_type_id = xmpp_ordered_listener_get_type_once ();
		g_once_init_leave (&xmpp_ordered_listener_type_id__once, xmpp_ordered_listener_type_id);
	}
	return xmpp_ordered_listener_type_id__once;
}

static void
_vala_xmpp_ordered_listener_get_property (GObject * object,
                                          guint property_id,
                                          GValue * value,
                                          GParamSpec * pspec)
{
	XmppOrderedListener * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, XMPP_TYPE_ORDERED_LISTENER, XmppOrderedListener);
	switch (property_id) {
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

void
xmpp_listener_holder_connect (XmppListenerHolder* self,
                              XmppOrderedListener* listener)
{
	GeeArrayList* _tmp0_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (listener != NULL);
	_tmp0_ = self->listeners;
	gee_abstract_collection_add ((GeeAbstractCollection*) _tmp0_, listener);
	xmpp_listener_holder_resort_list (self);
}

void
xmpp_listener_holder_disconnect (XmppListenerHolder* self,
                                 XmppOrderedListener* listener)
{
	GeeArrayList* _tmp0_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (listener != NULL);
	_tmp0_ = self->listeners;
	gee_abstract_collection_remove ((GeeAbstractCollection*) _tmp0_, listener);
	xmpp_listener_holder_resort_list (self);
}

static gboolean
_vala_string_array_contains (gchar* * stack,
                             gssize stack_length,
                             const gchar* needle)
{
	gssize i;
	for (i = 0; i < stack_length; i++) {
		if (g_strcmp0 (stack[i], needle) == 0) {
			return TRUE;
		}
	}
	return FALSE;
}

static gboolean
xmpp_listener_holder_set_contains_action (XmppListenerHolder* self,
                                          GeeList* s,
                                          gchar** actions,
                                          gint actions_length1)
{
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (s != NULL, FALSE);
	{
		GeeList* _l_list = NULL;
		gint _l_size = 0;
		GeeList* _tmp0_;
		gint _tmp1_;
		gint _tmp2_;
		gint _l_index = 0;
		_l_list = s;
		_tmp0_ = _l_list;
		_tmp1_ = gee_collection_get_size ((GeeCollection*) _tmp0_);
		_tmp2_ = _tmp1_;
		_l_size = _tmp2_;
		_l_index = -1;
		while (TRUE) {
			gint _tmp3_;
			gint _tmp4_;
			XmppOrderedListener* l = NULL;
			GeeList* _tmp5_;
			gpointer _tmp6_;
			XmppOrderedListener* _tmp7_;
			const gchar* _tmp8_;
			const gchar* _tmp9_;
			_l_index = _l_index + 1;
			_tmp3_ = _l_index;
			_tmp4_ = _l_size;
			if (!(_tmp3_ < _tmp4_)) {
				break;
			}
			_tmp5_ = _l_list;
			_tmp6_ = gee_list_get (_tmp5_, _l_index);
			l = (XmppOrderedListener*) _tmp6_;
			_tmp7_ = l;
			_tmp8_ = xmpp_ordered_listener_get_action_group (_tmp7_);
			_tmp9_ = _tmp8_;
			if (_vala_string_array_contains (actions, actions_length1, _tmp9_)) {
				result = TRUE;
				_g_object_unref0 (l);
				return result;
			}
			_g_object_unref0 (l);
		}
	}
	result = FALSE;
	return result;
}

static void
xmpp_listener_holder_resort_list (XmppListenerHolder* self)
{
	GeeArrayList* new_list = NULL;
	GeeArrayList* _tmp0_;
	GeeArrayList* remaining = NULL;
	GeeArrayList* _tmp1_;
	GeeArrayList* _tmp2_;
	GeeArrayList* _tmp3_;
	GeeArrayList* _tmp21_;
	GeeArrayList* _tmp22_;
	g_return_if_fail (self != NULL);
	_tmp0_ = gee_array_list_new (XMPP_TYPE_ORDERED_LISTENER, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
	new_list = _tmp0_;
	_tmp1_ = gee_array_list_new (XMPP_TYPE_ORDERED_LISTENER, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
	remaining = _tmp1_;
	_tmp2_ = remaining;
	_tmp3_ = self->listeners;
	gee_array_list_add_all (_tmp2_, (GeeCollection*) _tmp3_);
	while (TRUE) {
		GeeArrayList* _tmp4_;
		gint _tmp5_;
		gint _tmp6_;
		gboolean changed = FALSE;
		GeeIterator* iter = NULL;
		GeeArrayList* _tmp7_;
		GeeIterator* _tmp8_;
		_tmp4_ = remaining;
		_tmp5_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp4_);
		_tmp6_ = _tmp5_;
		if (!(_tmp6_ > 0)) {
			break;
		}
		changed = FALSE;
		_tmp7_ = remaining;
		_tmp8_ = gee_abstract_collection_iterator ((GeeAbstractCollection*) _tmp7_);
		iter = _tmp8_;
		while (TRUE) {
			GeeIterator* _tmp9_;
			GeeIterator* _tmp10_;
			XmppOrderedListener* l = NULL;
			GeeIterator* _tmp11_;
			gpointer _tmp12_;
			GeeArrayList* _tmp13_;
			XmppOrderedListener* _tmp14_;
			gchar** _tmp15_;
			gint _tmp15__length1;
			gint _tmp16_ = 0;
			gchar** _tmp17_;
			gint _tmp17__length1;
			_tmp9_ = iter;
			if (!gee_iterator_has_next (_tmp9_)) {
				break;
			}
			_tmp10_ = iter;
			gee_iterator_next (_tmp10_);
			_tmp11_ = iter;
			_tmp12_ = gee_iterator_get (_tmp11_);
			l = (XmppOrderedListener*) _tmp12_;
			_tmp13_ = remaining;
			_tmp14_ = l;
			_tmp15_ = xmpp_ordered_listener_get_after_actions (_tmp14_, &_tmp16_);
			_tmp15__length1 = _tmp16_;
			_tmp17_ = _tmp15_;
			_tmp17__length1 = _tmp15__length1;
			if (!xmpp_listener_holder_set_contains_action (self, (GeeList*) _tmp13_, _tmp17_, (gint) _tmp17__length1)) {
				GeeArrayList* _tmp18_;
				XmppOrderedListener* _tmp19_;
				GeeIterator* _tmp20_;
				_tmp18_ = new_list;
				_tmp19_ = l;
				gee_abstract_collection_add ((GeeAbstractCollection*) _tmp18_, _tmp19_);
				_tmp20_ = iter;
				gee_iterator_remove (_tmp20_);
				changed = TRUE;
			}
			_g_object_unref0 (l);
		}
		if (!changed) {
			g_error ("util.vala:80: Can't sort listeners");
		}
		_g_object_unref0 (iter);
	}
	_tmp21_ = new_list;
	_tmp22_ = _g_object_ref0 (_tmp21_);
	_g_object_unref0 (self->listeners);
	self->listeners = _tmp22_;
	_g_object_unref0 (remaining);
	_g_object_unref0 (new_list);
}

XmppListenerHolder*
xmpp_listener_holder_construct (GType object_type)
{
	XmppListenerHolder * self = NULL;
	self = (XmppListenerHolder*) g_object_new (object_type, NULL);
	return self;
}

static void
xmpp_listener_holder_class_init (XmppListenerHolderClass * klass,
                                 gpointer klass_data)
{
	xmpp_listener_holder_parent_class = g_type_class_peek_parent (klass);
	G_OBJECT_CLASS (klass)->finalize = xmpp_listener_holder_finalize;
}

static void
xmpp_listener_holder_instance_init (XmppListenerHolder * self,
                                    gpointer klass)
{
	GeeArrayList* _tmp0_;
	_tmp0_ = gee_array_list_new (XMPP_TYPE_ORDERED_LISTENER, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
	self->listeners = _tmp0_;
}

static void
xmpp_listener_holder_finalize (GObject * obj)
{
	XmppListenerHolder * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, XMPP_TYPE_LISTENER_HOLDER, XmppListenerHolder);
	_g_object_unref0 (self->listeners);
	G_OBJECT_CLASS (xmpp_listener_holder_parent_class)->finalize (obj);
}

static GType
xmpp_listener_holder_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (XmppListenerHolderClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) xmpp_listener_holder_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (XmppListenerHolder), 0, (GInstanceInitFunc) xmpp_listener_holder_instance_init, NULL };
	GType xmpp_listener_holder_type_id;
	xmpp_listener_holder_type_id = g_type_register_static (G_TYPE_OBJECT, "XmppListenerHolder", &g_define_type_info, G_TYPE_FLAG_ABSTRACT);
	return xmpp_listener_holder_type_id;
}

GType
xmpp_listener_holder_get_type (void)
{
	static volatile gsize xmpp_listener_holder_type_id__once = 0;
	if (g_once_init_enter (&xmpp_listener_holder_type_id__once)) {
		GType xmpp_listener_holder_type_id;
		xmpp_listener_holder_type_id = xmpp_listener_holder_get_type_once ();
		g_once_init_leave (&xmpp_listener_holder_type_id__once, xmpp_listener_holder_type_id);
	}
	return xmpp_listener_holder_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;
}

