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

#include "xmpp-vala.h"
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <glib-object.h>
#include <gee.h>
#include <gio/gio.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_XEP_JINGLE_FLAG_0_PROPERTY,
	XMPP_XEP_JINGLE_FLAG_NUM_PROPERTIES
};
static GParamSpec* xmpp_xep_jingle_flag_properties[XMPP_XEP_JINGLE_FLAG_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _gee_promise_unref0(var) ((var == NULL) ? NULL : (var = (gee_promise_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
typedef struct _XmppXepJingleFlagGetSessionData XmppXepJingleFlagGetSessionData;

struct _XmppXepJingleFlagGetSessionData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	XmppXepJingleFlag* self;
	gchar* sid;
	XmppXepJingleSession* result;
	GeeHashMap* _tmp0_;
	XmppXepJingleSession* _tmp1_;
	GeeHashMap* _tmp2_;
	gpointer _tmp3_;
	GeePromise* _tmp4_;
	GeeFuture* _tmp5_;
	GeeFuture* _tmp6_;
	gconstpointer _tmp7_;
	XmppXepJingleSession* _tmp8_;
	XmppXepJingleSession* _tmp9_;
	GeeHashMap* _tmp10_;
	gpointer _tmp11_;
	GError* _inner_error0_;
};

static gpointer xmpp_xep_jingle_flag_parent_class = NULL;
XmppFlagIdentity* xmpp_xep_jingle_flag_IDENTITY = NULL;

static void xmpp_xep_jingle_flag_get_session_data_free (gpointer _data);
static gboolean xmpp_xep_jingle_flag_get_session_co (XmppXepJingleFlagGetSessionData* _data_);
static void xmpp_xep_jingle_flag_get_session_ready (GObject* source_object,
                                             GAsyncResult* _res_,
                                             gpointer _user_data_);
static gchar* xmpp_xep_jingle_flag_real_get_ns (XmppXmppStreamFlag* base);
static gchar* xmpp_xep_jingle_flag_real_get_id (XmppXmppStreamFlag* base);
static void xmpp_xep_jingle_flag_finalize (GObject * obj);
static GType xmpp_xep_jingle_flag_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

void
xmpp_xep_jingle_flag_pre_add_session (XmppXepJingleFlag* self,
                                      const gchar* sid)
{
	GeePromise* promise = NULL;
	GeePromise* _tmp0_;
	GeeHashMap* _tmp1_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (sid != NULL);
	_tmp0_ = gee_promise_new (XMPP_XEP_JINGLE_TYPE_SESSION, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref);
	promise = _tmp0_;
	_tmp1_ = self->promises;
	gee_abstract_map_set ((GeeAbstractMap*) _tmp1_, sid, promise);
	_gee_promise_unref0 (promise);
}

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

void
xmpp_xep_jingle_flag_add_session (XmppXepJingleFlag* self,
                                  XmppXepJingleSession* session)
{
	GeeHashMap* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	GeeHashMap* _tmp12_;
	const gchar* _tmp13_;
	const gchar* _tmp14_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (session != NULL);
	_tmp0_ = self->promises;
	_tmp1_ = xmpp_xep_jingle_session_get_sid (session);
	_tmp2_ = _tmp1_;
	if (gee_abstract_map_has_key ((GeeAbstractMap*) _tmp0_, _tmp2_)) {
		GeeHashMap* _tmp3_;
		const gchar* _tmp4_;
		const gchar* _tmp5_;
		gpointer _tmp6_;
		GeePromise* _tmp7_;
		XmppXepJingleSession* _tmp8_;
		GeeHashMap* _tmp9_;
		const gchar* _tmp10_;
		const gchar* _tmp11_;
		_tmp3_ = self->promises;
		_tmp4_ = xmpp_xep_jingle_session_get_sid (session);
		_tmp5_ = _tmp4_;
		_tmp6_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp3_, _tmp5_);
		_tmp7_ = (GeePromise*) _tmp6_;
		_tmp8_ = _g_object_ref0 (session);
		gee_promise_set_value (_tmp7_, _tmp8_);
		_gee_promise_unref0 (_tmp7_);
		_tmp9_ = self->promises;
		_tmp10_ = xmpp_xep_jingle_session_get_sid (session);
		_tmp11_ = _tmp10_;
		gee_abstract_map_unset ((GeeAbstractMap*) _tmp9_, _tmp11_, NULL);
	}
	_tmp12_ = self->sessions;
	_tmp13_ = xmpp_xep_jingle_session_get_sid (session);
	_tmp14_ = _tmp13_;
	gee_abstract_map_set ((GeeAbstractMap*) _tmp12_, _tmp14_, session);
}

static void
xmpp_xep_jingle_flag_get_session_data_free (gpointer _data)
{
	XmppXepJingleFlagGetSessionData* _data_;
	_data_ = _data;
	_g_free0 (_data_->sid);
	_g_object_unref0 (_data_->result);
	_g_object_unref0 (_data_->self);
	g_slice_free (XmppXepJingleFlagGetSessionData, _data_);
}

void
xmpp_xep_jingle_flag_get_session (XmppXepJingleFlag* self,
                                  const gchar* sid,
                                  GAsyncReadyCallback _callback_,
                                  gpointer _user_data_)
{
	XmppXepJingleFlagGetSessionData* _data_;
	XmppXepJingleFlag* _tmp0_;
	gchar* _tmp1_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (sid != NULL);
	_data_ = g_slice_new0 (XmppXepJingleFlagGetSessionData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, xmpp_xep_jingle_flag_get_session_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = g_strdup (sid);
	_g_free0 (_data_->sid);
	_data_->sid = _tmp1_;
	xmpp_xep_jingle_flag_get_session_co (_data_);
}

XmppXepJingleSession*
xmpp_xep_jingle_flag_get_session_finish (XmppXepJingleFlag* self,
                                         GAsyncResult* _res_)
{
	XmppXepJingleSession* result;
	XmppXepJingleFlagGetSessionData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

static void
xmpp_xep_jingle_flag_get_session_ready (GObject* source_object,
                                        GAsyncResult* _res_,
                                        gpointer _user_data_)
{
	XmppXepJingleFlagGetSessionData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	xmpp_xep_jingle_flag_get_session_co (_data_);
}

static gboolean
xmpp_xep_jingle_flag_get_session_co (XmppXepJingleFlagGetSessionData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = _data_->self->promises;
	if (gee_abstract_map_has_key ((GeeAbstractMap*) _data_->_tmp0_, _data_->sid)) {
		_data_->_tmp2_ = _data_->self->promises;
		_data_->_tmp3_ = gee_abstract_map_get ((GeeAbstractMap*) _data_->_tmp2_, _data_->sid);
		_data_->_tmp4_ = (GeePromise*) _data_->_tmp3_;
		_data_->_tmp5_ = gee_promise_get_future (_data_->_tmp4_);
		_data_->_tmp6_ = _data_->_tmp5_;
		_data_->_state_ = 1;
		gee_future_wait_async (_data_->_tmp6_, xmpp_xep_jingle_flag_get_session_ready, _data_);
		return FALSE;
		_state_1:
		_data_->_tmp7_ = gee_future_wait_finish (_data_->_tmp6_, _data_->_res_, &_data_->_inner_error0_);
		_data_->_tmp8_ = (XmppXepJingleSession*) _data_->_tmp7_;
		_gee_promise_unref0 (_data_->_tmp4_);
		_data_->_tmp1_ = _data_->_tmp8_;
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
			g_clear_error (&_data_->_inner_error0_);
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
		_data_->_tmp9_ = _g_object_ref0 (_data_->_tmp1_);
		_data_->result = _data_->_tmp9_;
		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;
	}
	_data_->_tmp10_ = _data_->self->sessions;
	_data_->_tmp11_ = gee_abstract_map_get ((GeeAbstractMap*) _data_->_tmp10_, _data_->sid);
	_data_->result = (XmppXepJingleSession*) _data_->_tmp11_;
	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;
}

void
xmpp_xep_jingle_flag_remove_session (XmppXepJingleFlag* self,
                                     const gchar* sid)
{
	GeeHashMap* _tmp0_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (sid != NULL);
	_tmp0_ = self->sessions;
	gee_abstract_map_unset ((GeeAbstractMap*) _tmp0_, sid, NULL);
}

static gchar*
xmpp_xep_jingle_flag_real_get_ns (XmppXmppStreamFlag* base)
{
	XmppXepJingleFlag * self;
	gchar* _tmp0_;
	gchar* result;
	self = (XmppXepJingleFlag*) base;
	_tmp0_ = g_strdup (XMPP_XEP_JINGLE_NS_URI);
	result = _tmp0_;
	return result;
}

static gchar*
xmpp_xep_jingle_flag_real_get_id (XmppXmppStreamFlag* base)
{
	XmppXepJingleFlag * self;
	XmppFlagIdentity* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* result;
	self = (XmppXepJingleFlag*) base;
	_tmp0_ = xmpp_xep_jingle_flag_IDENTITY;
	_tmp1_ = xmpp_flag_identity_get_id (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = g_strdup (_tmp2_);
	result = _tmp3_;
	return result;
}

XmppXepJingleFlag*
xmpp_xep_jingle_flag_construct (GType object_type)
{
	XmppXepJingleFlag * self = NULL;
	self = (XmppXepJingleFlag*) xmpp_xmpp_stream_flag_construct (object_type);
	return self;
}

XmppXepJingleFlag*
xmpp_xep_jingle_flag_new (void)
{
	return xmpp_xep_jingle_flag_construct (XMPP_XEP_JINGLE_TYPE_FLAG);
}

static void
xmpp_xep_jingle_flag_class_init (XmppXepJingleFlagClass * klass,
                                 gpointer klass_data)
{
	XmppFlagIdentity* _tmp0_;
	xmpp_xep_jingle_flag_parent_class = g_type_class_peek_parent (klass);
	((XmppXmppStreamFlagClass *) klass)->get_ns = (gchar* (*) (XmppXmppStreamFlag*)) xmpp_xep_jingle_flag_real_get_ns;
	((XmppXmppStreamFlagClass *) klass)->get_id = (gchar* (*) (XmppXmppStreamFlag*)) xmpp_xep_jingle_flag_real_get_id;
	G_OBJECT_CLASS (klass)->finalize = xmpp_xep_jingle_flag_finalize;
	_tmp0_ = xmpp_flag_identity_new (XMPP_XEP_JINGLE_TYPE_FLAG, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, XMPP_XEP_JINGLE_NS_URI, "jingle");
	xmpp_xep_jingle_flag_IDENTITY = _tmp0_;
}

static void
xmpp_xep_jingle_flag_instance_init (XmppXepJingleFlag * self,
                                    gpointer klass)
{
	GeeHashMap* _tmp0_;
	GeeHashMap* _tmp1_;
	_tmp0_ = gee_hash_map_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, XMPP_XEP_JINGLE_TYPE_SESSION, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
	self->sessions = _tmp0_;
	_tmp1_ = gee_hash_map_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, GEE_TYPE_PROMISE, (GBoxedCopyFunc) gee_promise_ref, (GDestroyNotify) gee_promise_unref, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
	self->promises = _tmp1_;
}

static void
xmpp_xep_jingle_flag_finalize (GObject * obj)
{
	XmppXepJingleFlag * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, XMPP_XEP_JINGLE_TYPE_FLAG, XmppXepJingleFlag);
	_g_object_unref0 (self->sessions);
	_g_object_unref0 (self->promises);
	G_OBJECT_CLASS (xmpp_xep_jingle_flag_parent_class)->finalize (obj);
}

static GType
xmpp_xep_jingle_flag_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (XmppXepJingleFlagClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) xmpp_xep_jingle_flag_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (XmppXepJingleFlag), 0, (GInstanceInitFunc) xmpp_xep_jingle_flag_instance_init, NULL };
	GType xmpp_xep_jingle_flag_type_id;
	xmpp_xep_jingle_flag_type_id = g_type_register_static (XMPP_TYPE_XMPP_STREAM_FLAG, "XmppXepJingleFlag", &g_define_type_info, 0);
	return xmpp_xep_jingle_flag_type_id;
}

GType
xmpp_xep_jingle_flag_get_type (void)
{
	static volatile gsize xmpp_xep_jingle_flag_type_id__once = 0;
	if (g_once_init_enter (&xmpp_xep_jingle_flag_type_id__once)) {
		GType xmpp_xep_jingle_flag_type_id;
		xmpp_xep_jingle_flag_type_id = xmpp_xep_jingle_flag_get_type_once ();
		g_once_init_leave (&xmpp_xep_jingle_flag_type_id__once, xmpp_xep_jingle_flag_type_id);
	}
	return xmpp_xep_jingle_flag_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;
}

