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

#include "xmpp-vala.h"
#include <glib-object.h>
#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include <gee.h>
#include <gobject/gvaluecollector.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

#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _xmpp_stanza_entry_unref0(var) ((var == NULL) ? NULL : (var = (xmpp_stanza_entry_unref (var), NULL)))
#define _xmpp_xep_service_discovery_item_unref0(var) ((var == NULL) ? NULL : (var = (xmpp_xep_service_discovery_item_unref (var), NULL)))
#define _xmpp_jid_unref0(var) ((var == NULL) ? NULL : (var = (xmpp_jid_unref (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
typedef struct _XmppXepServiceDiscoveryParamSpecItemsResult XmppXepServiceDiscoveryParamSpecItemsResult;

struct _XmppXepServiceDiscoveryItemsResultPrivate {
	XmppIqStanza* _iq;
};

struct _XmppXepServiceDiscoveryParamSpecItemsResult {
	GParamSpec parent_instance;
};

static gint XmppXepServiceDiscoveryItemsResult_private_offset;
static gpointer xmpp_xep_service_discovery_items_result_parent_class = NULL;

static XmppXepServiceDiscoveryItemsResult* xmpp_xep_service_discovery_items_result_new_from_iq (XmppIqStanza* iq);
static XmppXepServiceDiscoveryItemsResult* xmpp_xep_service_discovery_items_result_construct_from_iq (GType object_type,
                                                                                               XmppIqStanza* iq);
static void xmpp_xep_service_discovery_items_result_set_iq (XmppXepServiceDiscoveryItemsResult* self,
                                                     XmppIqStanza* value);
static void xmpp_xep_service_discovery_items_result_finalize (XmppXepServiceDiscoveryItemsResult * obj);
static GType xmpp_xep_service_discovery_items_result_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
xmpp_xep_service_discovery_items_result_get_instance_private (XmppXepServiceDiscoveryItemsResult* self)
{
	return G_STRUCT_MEMBER_P (self, XmppXepServiceDiscoveryItemsResult_private_offset);
}

static XmppXepServiceDiscoveryItemsResult*
xmpp_xep_service_discovery_items_result_construct_from_iq (GType object_type,
                                                           XmppIqStanza* iq)
{
	XmppXepServiceDiscoveryItemsResult* self = NULL;
	g_return_val_if_fail (iq != NULL, NULL);
	self = (XmppXepServiceDiscoveryItemsResult*) g_type_create_instance (object_type);
	xmpp_xep_service_discovery_items_result_set_iq (self, iq);
	return self;
}

static XmppXepServiceDiscoveryItemsResult*
xmpp_xep_service_discovery_items_result_new_from_iq (XmppIqStanza* iq)
{
	return xmpp_xep_service_discovery_items_result_construct_from_iq (XMPP_XEP_SERVICE_DISCOVERY_TYPE_ITEMS_RESULT, iq);
}

XmppXepServiceDiscoveryItemsResult*
xmpp_xep_service_discovery_items_result_create_from_iq (XmppIqStanza* iq)
{
	const gchar* _tmp0_;
	const gchar* _tmp1_;
	XmppStanzaNode* _tmp2_;
	XmppStanzaNode* _tmp3_;
	XmppStanzaNode* _tmp4_;
	gboolean _tmp5_;
	XmppXepServiceDiscoveryItemsResult* _tmp6_;
	XmppXepServiceDiscoveryItemsResult* result;
	g_return_val_if_fail (iq != NULL, NULL);
	_tmp0_ = xmpp_stanza_get_type_ ((XmppStanza*) iq);
	_tmp1_ = _tmp0_;
	if (g_strcmp0 (_tmp1_, XMPP_IQ_STANZA_TYPE_RESULT) != 0) {
		result = NULL;
		return result;
	}
	_tmp2_ = ((XmppStanza*) iq)->stanza;
	_tmp3_ = xmpp_stanza_node_get_subnode (_tmp2_, "query", XMPP_XEP_SERVICE_DISCOVERY_NS_URI_ITEMS, FALSE);
	_tmp4_ = _tmp3_;
	_tmp5_ = _tmp4_ == NULL;
	_xmpp_stanza_entry_unref0 (_tmp4_);
	if (_tmp5_) {
		result = NULL;
		return result;
	}
	_tmp6_ = xmpp_xep_service_discovery_items_result_new_from_iq (iq);
	result = _tmp6_;
	return result;
}

XmppXepServiceDiscoveryItemsResult*
xmpp_xep_service_discovery_items_result_construct (GType object_type)
{
	XmppXepServiceDiscoveryItemsResult* self = NULL;
	self = (XmppXepServiceDiscoveryItemsResult*) g_type_create_instance (object_type);
	return self;
}

XmppXepServiceDiscoveryItemsResult*
xmpp_xep_service_discovery_items_result_new (void)
{
	return xmpp_xep_service_discovery_items_result_construct (XMPP_XEP_SERVICE_DISCOVERY_TYPE_ITEMS_RESULT);
}

XmppIqStanza*
xmpp_xep_service_discovery_items_result_get_iq (XmppXepServiceDiscoveryItemsResult* self)
{
	XmppIqStanza* result;
	XmppIqStanza* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_iq;
	result = _tmp0_;
	return result;
}

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

static void
xmpp_xep_service_discovery_items_result_set_iq (XmppXepServiceDiscoveryItemsResult* self,
                                                XmppIqStanza* value)
{
	XmppIqStanza* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = _g_object_ref0 (value);
	_g_object_unref0 (self->priv->_iq);
	self->priv->_iq = _tmp0_;
}

GeeArrayList*
xmpp_xep_service_discovery_items_result_get_items (XmppXepServiceDiscoveryItemsResult* self)
{
	GeeArrayList* result;
	GeeArrayList* ret = NULL;
	GeeArrayList* _tmp0_;
	GError* _inner_error0_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = gee_array_list_new (XMPP_XEP_SERVICE_DISCOVERY_TYPE_ITEM, (GBoxedCopyFunc) xmpp_xep_service_discovery_item_ref, (GDestroyNotify) xmpp_xep_service_discovery_item_unref, NULL, NULL, NULL);
	ret = _tmp0_;
	{
		GeeList* _feature_node_list = NULL;
		XmppIqStanza* _tmp1_;
		XmppStanzaNode* _tmp2_;
		XmppStanzaNode* _tmp3_;
		XmppStanzaNode* _tmp4_;
		GeeList* _tmp5_;
		GeeList* _tmp6_;
		gint _feature_node_size = 0;
		GeeList* _tmp7_;
		gint _tmp8_;
		gint _tmp9_;
		gint _feature_node_index = 0;
		_tmp1_ = self->priv->_iq;
		_tmp2_ = ((XmppStanza*) _tmp1_)->stanza;
		_tmp3_ = xmpp_stanza_node_get_subnode (_tmp2_, "query", XMPP_XEP_SERVICE_DISCOVERY_NS_URI_ITEMS, FALSE);
		_tmp4_ = _tmp3_;
		_tmp5_ = xmpp_stanza_node_get_subnodes (_tmp4_, "item", XMPP_XEP_SERVICE_DISCOVERY_NS_URI_ITEMS, FALSE);
		_tmp6_ = _tmp5_;
		_xmpp_stanza_entry_unref0 (_tmp4_);
		_feature_node_list = _tmp6_;
		_tmp7_ = _feature_node_list;
		_tmp8_ = gee_collection_get_size ((GeeCollection*) _tmp7_);
		_tmp9_ = _tmp8_;
		_feature_node_size = _tmp9_;
		_feature_node_index = -1;
		while (TRUE) {
			gint _tmp10_;
			gint _tmp11_;
			XmppStanzaNode* feature_node = NULL;
			GeeList* _tmp12_;
			gpointer _tmp13_;
			_feature_node_index = _feature_node_index + 1;
			_tmp10_ = _feature_node_index;
			_tmp11_ = _feature_node_size;
			if (!(_tmp10_ < _tmp11_)) {
				break;
			}
			_tmp12_ = _feature_node_list;
			_tmp13_ = gee_list_get (_tmp12_, _feature_node_index);
			feature_node = (XmppStanzaNode*) _tmp13_;
			{
				XmppJid* _tmp14_ = NULL;
				XmppStanzaNode* _tmp15_;
				const gchar* _tmp16_;
				XmppJid* _tmp17_;
				GeeArrayList* _tmp18_;
				XmppStanzaNode* _tmp19_;
				const gchar* _tmp20_;
				XmppStanzaNode* _tmp21_;
				const gchar* _tmp22_;
				XmppXepServiceDiscoveryItem* _tmp23_;
				XmppXepServiceDiscoveryItem* _tmp24_;
				_tmp15_ = feature_node;
				_tmp16_ = xmpp_stanza_node_get_attribute (_tmp15_, "jid", XMPP_XEP_SERVICE_DISCOVERY_NS_URI_ITEMS);
				_tmp17_ = xmpp_jid_new (_tmp16_, &_inner_error0_);
				_tmp14_ = _tmp17_;
				if (G_UNLIKELY (_inner_error0_ != NULL)) {
					if (_inner_error0_->domain == XMPP_INVALID_JID_ERROR) {
						goto __catch0_xmpp_invalid_jid_error;
					}
					_xmpp_stanza_entry_unref0 (feature_node);
					_g_object_unref0 (_feature_node_list);
					_g_object_unref0 (ret);
					g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
					g_clear_error (&_inner_error0_);
					return NULL;
				}
				_tmp18_ = ret;
				_tmp19_ = feature_node;
				_tmp20_ = xmpp_stanza_node_get_attribute (_tmp19_, "name", XMPP_XEP_SERVICE_DISCOVERY_NS_URI_ITEMS);
				_tmp21_ = feature_node;
				_tmp22_ = xmpp_stanza_node_get_attribute (_tmp21_, "node", XMPP_XEP_SERVICE_DISCOVERY_NS_URI_ITEMS);
				_tmp23_ = xmpp_xep_service_discovery_item_new (_tmp14_, _tmp20_, _tmp22_);
				_tmp24_ = _tmp23_;
				gee_abstract_collection_add ((GeeAbstractCollection*) _tmp18_, _tmp24_);
				_xmpp_xep_service_discovery_item_unref0 (_tmp24_);
				_xmpp_jid_unref0 (_tmp14_);
			}
			goto __finally0;
			__catch0_xmpp_invalid_jid_error:
			{
				GError* e = NULL;
				GError* _tmp25_;
				const gchar* _tmp26_;
				e = _inner_error0_;
				_inner_error0_ = NULL;
				_tmp25_ = e;
				_tmp26_ = _tmp25_->message;
				g_warning ("items_result.vala:17: Ignoring service at invalid Jid: %s", _tmp26_);
				_g_error_free0 (e);
			}
			__finally0:
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				_xmpp_stanza_entry_unref0 (feature_node);
				_g_object_unref0 (_feature_node_list);
				_g_object_unref0 (ret);
				g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
				g_clear_error (&_inner_error0_);
				return NULL;
			}
			_xmpp_stanza_entry_unref0 (feature_node);
		}
		_g_object_unref0 (_feature_node_list);
	}
	result = ret;
	return result;
}

static void
xmpp_xep_service_discovery_value_items_result_init (GValue* value)
{
	value->data[0].v_pointer = NULL;
}

static void
xmpp_xep_service_discovery_value_items_result_free_value (GValue* value)
{
	if (value->data[0].v_pointer) {
		xmpp_xep_service_discovery_items_result_unref (value->data[0].v_pointer);
	}
}

static void
xmpp_xep_service_discovery_value_items_result_copy_value (const GValue* src_value,
                                                          GValue* dest_value)
{
	if (src_value->data[0].v_pointer) {
		dest_value->data[0].v_pointer = xmpp_xep_service_discovery_items_result_ref (src_value->data[0].v_pointer);
	} else {
		dest_value->data[0].v_pointer = NULL;
	}
}

static gpointer
xmpp_xep_service_discovery_value_items_result_peek_pointer (const GValue* value)
{
	return value->data[0].v_pointer;
}

static gchar*
xmpp_xep_service_discovery_value_items_result_collect_value (GValue* value,
                                                             guint n_collect_values,
                                                             GTypeCValue* collect_values,
                                                             guint collect_flags)
{
	if (collect_values[0].v_pointer) {
		XmppXepServiceDiscoveryItemsResult * object;
		object = collect_values[0].v_pointer;
		if (object->parent_instance.g_class == NULL) {
			return g_strconcat ("invalid unclassed object pointer for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		} else if (!g_value_type_compatible (G_TYPE_FROM_INSTANCE (object), G_VALUE_TYPE (value))) {
			return g_strconcat ("invalid object type `", g_type_name (G_TYPE_FROM_INSTANCE (object)), "' for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		}
		value->data[0].v_pointer = xmpp_xep_service_discovery_items_result_ref (object);
	} else {
		value->data[0].v_pointer = NULL;
	}
	return NULL;
}

static gchar*
xmpp_xep_service_discovery_value_items_result_lcopy_value (const GValue* value,
                                                           guint n_collect_values,
                                                           GTypeCValue* collect_values,
                                                           guint collect_flags)
{
	XmppXepServiceDiscoveryItemsResult ** object_p;
	object_p = collect_values[0].v_pointer;
	if (!object_p) {
		return g_strdup_printf ("value location for `%s' passed as NULL", G_VALUE_TYPE_NAME (value));
	}
	if (!value->data[0].v_pointer) {
		*object_p = NULL;
	} else if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
		*object_p = value->data[0].v_pointer;
	} else {
		*object_p = xmpp_xep_service_discovery_items_result_ref (value->data[0].v_pointer);
	}
	return NULL;
}

GParamSpec*
xmpp_xep_service_discovery_param_spec_items_result (const gchar* name,
                                                    const gchar* nick,
                                                    const gchar* blurb,
                                                    GType object_type,
                                                    GParamFlags flags)
{
	XmppXepServiceDiscoveryParamSpecItemsResult* spec;
	g_return_val_if_fail (g_type_is_a (object_type, XMPP_XEP_SERVICE_DISCOVERY_TYPE_ITEMS_RESULT), NULL);
	spec = g_param_spec_internal (G_TYPE_PARAM_OBJECT, name, nick, blurb, flags);
	G_PARAM_SPEC (spec)->value_type = object_type;
	return G_PARAM_SPEC (spec);
}

gpointer
xmpp_xep_service_discovery_value_get_items_result (const GValue* value)
{
	g_return_val_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, XMPP_XEP_SERVICE_DISCOVERY_TYPE_ITEMS_RESULT), NULL);
	return value->data[0].v_pointer;
}

void
xmpp_xep_service_discovery_value_set_items_result (GValue* value,
                                                   gpointer v_object)
{
	XmppXepServiceDiscoveryItemsResult * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, XMPP_XEP_SERVICE_DISCOVERY_TYPE_ITEMS_RESULT));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, XMPP_XEP_SERVICE_DISCOVERY_TYPE_ITEMS_RESULT));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
		xmpp_xep_service_discovery_items_result_ref (value->data[0].v_pointer);
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		xmpp_xep_service_discovery_items_result_unref (old);
	}
}

void
xmpp_xep_service_discovery_value_take_items_result (GValue* value,
                                                    gpointer v_object)
{
	XmppXepServiceDiscoveryItemsResult * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, XMPP_XEP_SERVICE_DISCOVERY_TYPE_ITEMS_RESULT));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, XMPP_XEP_SERVICE_DISCOVERY_TYPE_ITEMS_RESULT));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		xmpp_xep_service_discovery_items_result_unref (old);
	}
}

static void
xmpp_xep_service_discovery_items_result_class_init (XmppXepServiceDiscoveryItemsResultClass * klass,
                                                    gpointer klass_data)
{
	xmpp_xep_service_discovery_items_result_parent_class = g_type_class_peek_parent (klass);
	((XmppXepServiceDiscoveryItemsResultClass *) klass)->finalize = xmpp_xep_service_discovery_items_result_finalize;
	g_type_class_adjust_private_offset (klass, &XmppXepServiceDiscoveryItemsResult_private_offset);
}

static void
xmpp_xep_service_discovery_items_result_instance_init (XmppXepServiceDiscoveryItemsResult * self,
                                                       gpointer klass)
{
	self->priv = xmpp_xep_service_discovery_items_result_get_instance_private (self);
	self->ref_count = 1;
}

static void
xmpp_xep_service_discovery_items_result_finalize (XmppXepServiceDiscoveryItemsResult * obj)
{
	XmppXepServiceDiscoveryItemsResult * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, XMPP_XEP_SERVICE_DISCOVERY_TYPE_ITEMS_RESULT, XmppXepServiceDiscoveryItemsResult);
	g_signal_handlers_destroy (self);
	_g_object_unref0 (self->priv->_iq);
}

static GType
xmpp_xep_service_discovery_items_result_get_type_once (void)
{
	static const GTypeValueTable g_define_type_value_table = { xmpp_xep_service_discovery_value_items_result_init, xmpp_xep_service_discovery_value_items_result_free_value, xmpp_xep_service_discovery_value_items_result_copy_value, xmpp_xep_service_discovery_value_items_result_peek_pointer, "p", xmpp_xep_service_discovery_value_items_result_collect_value, "p", xmpp_xep_service_discovery_value_items_result_lcopy_value };
	static const GTypeInfo g_define_type_info = { sizeof (XmppXepServiceDiscoveryItemsResultClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) xmpp_xep_service_discovery_items_result_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (XmppXepServiceDiscoveryItemsResult), 0, (GInstanceInitFunc) xmpp_xep_service_discovery_items_result_instance_init, &g_define_type_value_table };
	static const GTypeFundamentalInfo g_define_type_fundamental_info = { (G_TYPE_FLAG_CLASSED | G_TYPE_FLAG_INSTANTIATABLE | G_TYPE_FLAG_DERIVABLE | G_TYPE_FLAG_DEEP_DERIVABLE) };
	GType xmpp_xep_service_discovery_items_result_type_id;
	xmpp_xep_service_discovery_items_result_type_id = g_type_register_fundamental (g_type_fundamental_next (), "XmppXepServiceDiscoveryItemsResult", &g_define_type_info, &g_define_type_fundamental_info, 0);
	XmppXepServiceDiscoveryItemsResult_private_offset = g_type_add_instance_private (xmpp_xep_service_discovery_items_result_type_id, sizeof (XmppXepServiceDiscoveryItemsResultPrivate));
	return xmpp_xep_service_discovery_items_result_type_id;
}

GType
xmpp_xep_service_discovery_items_result_get_type (void)
{
	static volatile gsize xmpp_xep_service_discovery_items_result_type_id__once = 0;
	if (g_once_init_enter (&xmpp_xep_service_discovery_items_result_type_id__once)) {
		GType xmpp_xep_service_discovery_items_result_type_id;
		xmpp_xep_service_discovery_items_result_type_id = xmpp_xep_service_discovery_items_result_get_type_once ();
		g_once_init_leave (&xmpp_xep_service_discovery_items_result_type_id__once, xmpp_xep_service_discovery_items_result_type_id);
	}
	return xmpp_xep_service_discovery_items_result_type_id__once;
}

gpointer
xmpp_xep_service_discovery_items_result_ref (gpointer instance)
{
	XmppXepServiceDiscoveryItemsResult * self;
	self = instance;
	g_atomic_int_inc (&self->ref_count);
	return instance;
}

void
xmpp_xep_service_discovery_items_result_unref (gpointer instance)
{
	XmppXepServiceDiscoveryItemsResult * self;
	self = instance;
	if (g_atomic_int_dec_and_test (&self->ref_count)) {
		XMPP_XEP_SERVICE_DISCOVERY_ITEMS_RESULT_GET_CLASS (self)->finalize (self);
		g_type_free_instance ((GTypeInstance *) self);
	}
}

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;
}

