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

#include "libdino.h"
#include <gee.h>
#include <glib-object.h>
#include "xmpp-vala.h"
#include <glib.h>
#include <stdlib.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  {
	DINO_PRESENCE_MANAGER_0_PROPERTY,
	DINO_PRESENCE_MANAGER_ID_PROPERTY,
	DINO_PRESENCE_MANAGER_NUM_PROPERTIES
};
static GParamSpec* dino_presence_manager_properties[DINO_PRESENCE_MANAGER_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _xmpp_jid_unref0(var) ((var == NULL) ? NULL : (var = (xmpp_jid_unref (var), NULL)))
typedef struct _Block34Data Block34Data;
enum  {
	DINO_PRESENCE_MANAGER_SHOW_RECEIVED_SIGNAL,
	DINO_PRESENCE_MANAGER_RECEIVED_OFFLINE_PRESENCE_SIGNAL,
	DINO_PRESENCE_MANAGER_RECEIVED_SUBSCRIPTION_REQUEST_SIGNAL,
	DINO_PRESENCE_MANAGER_RECEIVED_SUBSCRIPTION_APPROVAL_SIGNAL,
	DINO_PRESENCE_MANAGER_NUM_SIGNALS
};
static guint dino_presence_manager_signals[DINO_PRESENCE_MANAGER_NUM_SIGNALS] = {0};

struct _DinoPresenceManagerPrivate {
	DinoStreamInteractor* stream_interactor;
	GeeHashMap* resources;
	GRecMutex __lock_resources;
	GeeList* subscription_requests;
};

struct _Block34Data {
	int _ref_count_;
	DinoPresenceManager* self;
	DinoEntitiesAccount* account;
};

static gint DinoPresenceManager_private_offset;
static gpointer dino_presence_manager_parent_class = NULL;
DinoModuleIdentity* dino_presence_manager_IDENTITY = NULL;
static DinoStreamInteractionModuleIface * dino_presence_manager_dino_stream_interaction_module_parent_iface = NULL;

static guint _xmpp_jid_hash_bare_func_gee_hash_data_func (gconstpointer v,
                                                   gpointer self);
static gboolean _xmpp_jid_equals_bare_func_gee_equal_data_func (gconstpointer a,
                                                         gconstpointer b,
                                                         gpointer self);
static gboolean _xmpp_jid_equals_func_gee_equal_data_func (gconstpointer a,
                                                    gconstpointer b,
                                                    gpointer self);
static DinoPresenceManager* dino_presence_manager_new (DinoStreamInteractor* stream_interactor);
static DinoPresenceManager* dino_presence_manager_construct (GType object_type,
                                                      DinoStreamInteractor* stream_interactor);
static void dino_presence_manager_on_account_added (DinoPresenceManager* self,
                                             DinoEntitiesAccount* account);
static void _dino_presence_manager_on_account_added_dino_stream_interactor_account_added (DinoStreamInteractor* _sender,
                                                                                   DinoEntitiesAccount* account,
                                                                                   gpointer self);
static Block34Data* block34_data_ref (Block34Data* _data34_);
static void block34_data_unref (void * _userdata_);
static void __lambda65_ (Block34Data* _data34_,
                  XmppXmppStream* stream,
                  XmppJid* jid,
                  const gchar* show);
static void dino_presence_manager_on_received_available_show (DinoPresenceManager* self,
                                                       DinoEntitiesAccount* account,
                                                       XmppJid* jid,
                                                       const gchar* show);
static void ___lambda65__xmpp_presence_module_received_available_show (XmppPresenceModule* _sender,
                                                                XmppXmppStream* stream,
                                                                XmppJid* jid,
                                                                const gchar* show,
                                                                gpointer self);
static void __lambda66_ (Block34Data* _data34_,
                  XmppXmppStream* stream,
                  XmppPresenceStanza* presence);
static void dino_presence_manager_on_received_unavailable (DinoPresenceManager* self,
                                                    DinoEntitiesAccount* account,
                                                    XmppJid* jid);
static void ___lambda66__xmpp_presence_module_received_unavailable (XmppPresenceModule* _sender,
                                                             XmppXmppStream* stream,
                                                             XmppPresenceStanza* presence,
                                                             gpointer self);
static void __lambda67_ (Block34Data* _data34_,
                  XmppXmppStream* stream,
                  XmppJid* jid);
static void ___lambda67__xmpp_presence_module_received_subscription_request (XmppPresenceModule* _sender,
                                                                      XmppXmppStream* stream,
                                                                      XmppJid* jid,
                                                                      gpointer self);
static void __lambda68_ (Block34Data* _data34_,
                  XmppXmppStream* stream,
                  XmppJid* jid);
static void ___lambda68__xmpp_presence_module_received_subscription_approval (XmppPresenceModule* _sender,
                                                                       XmppXmppStream* stream,
                                                                       XmppJid* jid,
                                                                       gpointer self);
static void g_cclosure_user_marshal_VOID__XMPP_JID_OBJECT (GClosure * closure,
                                                    GValue * return_value,
                                                    guint n_param_values,
                                                    const GValue * param_values,
                                                    gpointer invocation_hint,
                                                    gpointer marshal_data);
static void dino_presence_manager_finalize (GObject * obj);
static GType dino_presence_manager_get_type_once (void);
static void _vala_dino_presence_manager_get_property (GObject * object,
                                               guint property_id,
                                               GValue * value,
                                               GParamSpec * pspec);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
dino_presence_manager_get_instance_private (DinoPresenceManager* self)
{
	return G_STRUCT_MEMBER_P (self, DinoPresenceManager_private_offset);
}

static guint
_xmpp_jid_hash_bare_func_gee_hash_data_func (gconstpointer v,
                                             gpointer self)
{
	guint result;
	result = xmpp_jid_hash_bare_func ((XmppJid*) v);
	return result;
}

static gboolean
_xmpp_jid_equals_bare_func_gee_equal_data_func (gconstpointer a,
                                                gconstpointer b,
                                                gpointer self)
{
	gboolean result;
	result = xmpp_jid_equals_bare_func ((XmppJid*) a, (XmppJid*) b);
	return result;
}

static gboolean
_xmpp_jid_equals_func_gee_equal_data_func (gconstpointer a,
                                           gconstpointer b,
                                           gpointer self)
{
	gboolean result;
	result = xmpp_jid_equals_func ((XmppJid*) a, (XmppJid*) b);
	return result;
}

void
dino_presence_manager_start (DinoStreamInteractor* stream_interactor)
{
	DinoPresenceManager* m = NULL;
	DinoPresenceManager* _tmp0_;
	g_return_if_fail (stream_interactor != NULL);
	_tmp0_ = dino_presence_manager_new (stream_interactor);
	m = _tmp0_;
	dino_stream_interactor_add_module (stream_interactor, (DinoStreamInteractionModule*) m);
	_g_object_unref0 (m);
}

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

static void
_dino_presence_manager_on_account_added_dino_stream_interactor_account_added (DinoStreamInteractor* _sender,
                                                                              DinoEntitiesAccount* account,
                                                                              gpointer self)
{
	dino_presence_manager_on_account_added ((DinoPresenceManager*) self, account);
}

static DinoPresenceManager*
dino_presence_manager_construct (GType object_type,
                                 DinoStreamInteractor* stream_interactor)
{
	DinoPresenceManager * self = NULL;
	DinoStreamInteractor* _tmp0_;
	g_return_val_if_fail (stream_interactor != NULL, NULL);
	self = (DinoPresenceManager*) g_object_new (object_type, NULL);
	_tmp0_ = _g_object_ref0 (stream_interactor);
	_g_object_unref0 (self->priv->stream_interactor);
	self->priv->stream_interactor = _tmp0_;
	g_signal_connect_object (stream_interactor, "account-added", (GCallback) _dino_presence_manager_on_account_added_dino_stream_interactor_account_added, self, 0);
	return self;
}

static DinoPresenceManager*
dino_presence_manager_new (DinoStreamInteractor* stream_interactor)
{
	return dino_presence_manager_construct (DINO_TYPE_PRESENCE_MANAGER, stream_interactor);
}

gchar*
dino_presence_manager_get_last_show (DinoPresenceManager* self,
                                     XmppJid* jid,
                                     DinoEntitiesAccount* account)
{
	XmppXmppStream* stream = NULL;
	DinoStreamInteractor* _tmp0_;
	XmppXmppStream* _tmp1_;
	XmppXmppStream* _tmp2_;
	XmppPresenceStanza* presence = NULL;
	XmppXmppStream* _tmp3_;
	XmppFlagIdentity* _tmp4_;
	gpointer _tmp5_;
	XmppPresenceFlag* _tmp6_;
	XmppPresenceStanza* _tmp7_;
	XmppPresenceStanza* _tmp8_;
	XmppPresenceStanza* _tmp9_;
	XmppPresenceStanza* _tmp10_;
	const gchar* _tmp11_;
	const gchar* _tmp12_;
	gchar* _tmp13_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (jid != NULL, NULL);
	g_return_val_if_fail (account != NULL, NULL);
	_tmp0_ = self->priv->stream_interactor;
	_tmp1_ = dino_stream_interactor_get_stream (_tmp0_, account);
	stream = _tmp1_;
	_tmp2_ = stream;
	if (_tmp2_ == NULL) {
		result = NULL;
		_g_object_unref0 (stream);
		return result;
	}
	_tmp3_ = stream;
	_tmp4_ = xmpp_presence_flag_IDENTITY;
	_tmp5_ = xmpp_xmpp_stream_get_flag (_tmp3_, XMPP_PRESENCE_TYPE_FLAG, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp4_);
	_tmp6_ = (XmppPresenceFlag*) _tmp5_;
	_tmp7_ = xmpp_presence_flag_get_presence (_tmp6_, jid);
	_tmp8_ = _tmp7_;
	_g_object_unref0 (_tmp6_);
	presence = _tmp8_;
	_tmp9_ = presence;
	if (_tmp9_ == NULL) {
		result = NULL;
		_g_object_unref0 (presence);
		_g_object_unref0 (stream);
		return result;
	}
	_tmp10_ = presence;
	_tmp11_ = xmpp_presence_stanza_get_show (_tmp10_);
	_tmp12_ = _tmp11_;
	_tmp13_ = g_strdup (_tmp12_);
	result = _tmp13_;
	_g_object_unref0 (presence);
	_g_object_unref0 (stream);
	return result;
}

GeeList*
dino_presence_manager_get_full_jids (DinoPresenceManager* self,
                                     XmppJid* jid,
                                     DinoEntitiesAccount* account)
{
	XmppXmppStream* stream = NULL;
	DinoStreamInteractor* _tmp0_;
	XmppXmppStream* _tmp1_;
	XmppXmppStream* _tmp2_;
	GeeList* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (jid != NULL, NULL);
	g_return_val_if_fail (account != NULL, NULL);
	_tmp0_ = self->priv->stream_interactor;
	_tmp1_ = dino_stream_interactor_get_stream (_tmp0_, account);
	stream = _tmp1_;
	_tmp2_ = stream;
	if (_tmp2_ != NULL) {
		XmppPresenceFlag* flag = NULL;
		XmppXmppStream* _tmp3_;
		XmppFlagIdentity* _tmp4_;
		gpointer _tmp5_;
		XmppPresenceFlag* _tmp6_;
		XmppPresenceFlag* _tmp7_;
		XmppJid* _tmp8_;
		XmppJid* _tmp9_;
		XmppJid* _tmp10_;
		GeeList* _tmp11_;
		GeeList* _tmp12_;
		_tmp3_ = stream;
		_tmp4_ = xmpp_presence_flag_IDENTITY;
		_tmp5_ = xmpp_xmpp_stream_get_flag (_tmp3_, XMPP_PRESENCE_TYPE_FLAG, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp4_);
		flag = (XmppPresenceFlag*) _tmp5_;
		_tmp6_ = flag;
		if (_tmp6_ == NULL) {
			result = NULL;
			_g_object_unref0 (flag);
			_g_object_unref0 (stream);
			return result;
		}
		_tmp7_ = flag;
		_tmp8_ = xmpp_jid_get_bare_jid (jid);
		_tmp9_ = _tmp8_;
		_tmp10_ = _tmp9_;
		_tmp11_ = xmpp_presence_flag_get_resources (_tmp7_, _tmp10_);
		_tmp12_ = _tmp11_;
		_xmpp_jid_unref0 (_tmp10_);
		result = _tmp12_;
		_g_object_unref0 (flag);
		_g_object_unref0 (stream);
		return result;
	}
	result = NULL;
	_g_object_unref0 (stream);
	return result;
}

gboolean
dino_presence_manager_exists_subscription_request (DinoPresenceManager* self,
                                                   DinoEntitiesAccount* account,
                                                   XmppJid* jid)
{
	GeeList* _tmp0_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (account != NULL, FALSE);
	g_return_val_if_fail (jid != NULL, FALSE);
	_tmp0_ = self->priv->subscription_requests;
	result = gee_collection_contains ((GeeCollection*) _tmp0_, jid);
	return result;
}

void
dino_presence_manager_request_subscription (DinoPresenceManager* self,
                                            DinoEntitiesAccount* account,
                                            XmppJid* jid)
{
	XmppXmppStream* stream = NULL;
	DinoStreamInteractor* _tmp0_;
	XmppXmppStream* _tmp1_;
	XmppXmppStream* _tmp2_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (account != NULL);
	g_return_if_fail (jid != NULL);
	_tmp0_ = self->priv->stream_interactor;
	_tmp1_ = dino_stream_interactor_get_stream (_tmp0_, account);
	stream = _tmp1_;
	_tmp2_ = stream;
	if (_tmp2_ != NULL) {
		XmppXmppStream* _tmp3_;
		XmppModuleIdentity* _tmp4_;
		gpointer _tmp5_;
		XmppPresenceModule* _tmp6_;
		XmppXmppStream* _tmp7_;
		XmppJid* _tmp8_;
		XmppJid* _tmp9_;
		XmppJid* _tmp10_;
		_tmp3_ = stream;
		_tmp4_ = xmpp_presence_module_IDENTITY;
		_tmp5_ = xmpp_xmpp_stream_get_module (_tmp3_, XMPP_PRESENCE_TYPE_MODULE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp4_);
		_tmp6_ = (XmppPresenceModule*) _tmp5_;
		_tmp7_ = stream;
		_tmp8_ = xmpp_jid_get_bare_jid (jid);
		_tmp9_ = _tmp8_;
		_tmp10_ = _tmp9_;
		xmpp_presence_module_request_subscription (_tmp6_, _tmp7_, _tmp10_);
		_xmpp_jid_unref0 (_tmp10_);
		_g_object_unref0 (_tmp6_);
	}
	_g_object_unref0 (stream);
}

void
dino_presence_manager_approve_subscription (DinoPresenceManager* self,
                                            DinoEntitiesAccount* account,
                                            XmppJid* jid)
{
	XmppXmppStream* stream = NULL;
	DinoStreamInteractor* _tmp0_;
	XmppXmppStream* _tmp1_;
	XmppXmppStream* _tmp2_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (account != NULL);
	g_return_if_fail (jid != NULL);
	_tmp0_ = self->priv->stream_interactor;
	_tmp1_ = dino_stream_interactor_get_stream (_tmp0_, account);
	stream = _tmp1_;
	_tmp2_ = stream;
	if (_tmp2_ != NULL) {
		XmppXmppStream* _tmp3_;
		XmppModuleIdentity* _tmp4_;
		gpointer _tmp5_;
		XmppPresenceModule* _tmp6_;
		XmppXmppStream* _tmp7_;
		XmppJid* _tmp8_;
		XmppJid* _tmp9_;
		XmppJid* _tmp10_;
		GeeList* _tmp11_;
		_tmp3_ = stream;
		_tmp4_ = xmpp_presence_module_IDENTITY;
		_tmp5_ = xmpp_xmpp_stream_get_module (_tmp3_, XMPP_PRESENCE_TYPE_MODULE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp4_);
		_tmp6_ = (XmppPresenceModule*) _tmp5_;
		_tmp7_ = stream;
		_tmp8_ = xmpp_jid_get_bare_jid (jid);
		_tmp9_ = _tmp8_;
		_tmp10_ = _tmp9_;
		xmpp_presence_module_approve_subscription (_tmp6_, _tmp7_, _tmp10_);
		_xmpp_jid_unref0 (_tmp10_);
		_g_object_unref0 (_tmp6_);
		_tmp11_ = self->priv->subscription_requests;
		gee_collection_remove ((GeeCollection*) _tmp11_, jid);
	}
	_g_object_unref0 (stream);
}

void
dino_presence_manager_deny_subscription (DinoPresenceManager* self,
                                         DinoEntitiesAccount* account,
                                         XmppJid* jid)
{
	XmppXmppStream* stream = NULL;
	DinoStreamInteractor* _tmp0_;
	XmppXmppStream* _tmp1_;
	XmppXmppStream* _tmp2_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (account != NULL);
	g_return_if_fail (jid != NULL);
	_tmp0_ = self->priv->stream_interactor;
	_tmp1_ = dino_stream_interactor_get_stream (_tmp0_, account);
	stream = _tmp1_;
	_tmp2_ = stream;
	if (_tmp2_ != NULL) {
		XmppXmppStream* _tmp3_;
		XmppModuleIdentity* _tmp4_;
		gpointer _tmp5_;
		XmppPresenceModule* _tmp6_;
		XmppXmppStream* _tmp7_;
		XmppJid* _tmp8_;
		XmppJid* _tmp9_;
		XmppJid* _tmp10_;
		GeeList* _tmp11_;
		_tmp3_ = stream;
		_tmp4_ = xmpp_presence_module_IDENTITY;
		_tmp5_ = xmpp_xmpp_stream_get_module (_tmp3_, XMPP_PRESENCE_TYPE_MODULE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp4_);
		_tmp6_ = (XmppPresenceModule*) _tmp5_;
		_tmp7_ = stream;
		_tmp8_ = xmpp_jid_get_bare_jid (jid);
		_tmp9_ = _tmp8_;
		_tmp10_ = _tmp9_;
		xmpp_presence_module_deny_subscription (_tmp6_, _tmp7_, _tmp10_);
		_xmpp_jid_unref0 (_tmp10_);
		_g_object_unref0 (_tmp6_);
		_tmp11_ = self->priv->subscription_requests;
		gee_collection_remove ((GeeCollection*) _tmp11_, jid);
	}
	_g_object_unref0 (stream);
}

void
dino_presence_manager_cancel_subscription (DinoPresenceManager* self,
                                           DinoEntitiesAccount* account,
                                           XmppJid* jid)
{
	XmppXmppStream* stream = NULL;
	DinoStreamInteractor* _tmp0_;
	XmppXmppStream* _tmp1_;
	XmppXmppStream* _tmp2_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (account != NULL);
	g_return_if_fail (jid != NULL);
	_tmp0_ = self->priv->stream_interactor;
	_tmp1_ = dino_stream_interactor_get_stream (_tmp0_, account);
	stream = _tmp1_;
	_tmp2_ = stream;
	if (_tmp2_ != NULL) {
		XmppXmppStream* _tmp3_;
		XmppModuleIdentity* _tmp4_;
		gpointer _tmp5_;
		XmppPresenceModule* _tmp6_;
		XmppXmppStream* _tmp7_;
		XmppJid* _tmp8_;
		XmppJid* _tmp9_;
		XmppJid* _tmp10_;
		_tmp3_ = stream;
		_tmp4_ = xmpp_presence_module_IDENTITY;
		_tmp5_ = xmpp_xmpp_stream_get_module (_tmp3_, XMPP_PRESENCE_TYPE_MODULE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp4_);
		_tmp6_ = (XmppPresenceModule*) _tmp5_;
		_tmp7_ = stream;
		_tmp8_ = xmpp_jid_get_bare_jid (jid);
		_tmp9_ = _tmp8_;
		_tmp10_ = _tmp9_;
		xmpp_presence_module_cancel_subscription (_tmp6_, _tmp7_, _tmp10_);
		_xmpp_jid_unref0 (_tmp10_);
		_g_object_unref0 (_tmp6_);
	}
	_g_object_unref0 (stream);
}

static Block34Data*
block34_data_ref (Block34Data* _data34_)
{
	g_atomic_int_inc (&_data34_->_ref_count_);
	return _data34_;
}

static void
block34_data_unref (void * _userdata_)
{
	Block34Data* _data34_;
	_data34_ = (Block34Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data34_->_ref_count_)) {
		DinoPresenceManager* self;
		self = _data34_->self;
		_g_object_unref0 (_data34_->account);
		_g_object_unref0 (self);
		g_slice_free (Block34Data, _data34_);
	}
}

static void
__lambda65_ (Block34Data* _data34_,
             XmppXmppStream* stream,
             XmppJid* jid,
             const gchar* show)
{
	DinoPresenceManager* self;
	self = _data34_->self;
	g_return_if_fail (stream != NULL);
	g_return_if_fail (jid != NULL);
	g_return_if_fail (show != NULL);
	dino_presence_manager_on_received_available_show (self, _data34_->account, jid, show);
}

static void
___lambda65__xmpp_presence_module_received_available_show (XmppPresenceModule* _sender,
                                                           XmppXmppStream* stream,
                                                           XmppJid* jid,
                                                           const gchar* show,
                                                           gpointer self)
{
	__lambda65_ (self, stream, jid, show);
}

static void
__lambda66_ (Block34Data* _data34_,
             XmppXmppStream* stream,
             XmppPresenceStanza* presence)
{
	DinoPresenceManager* self;
	XmppJid* _tmp0_;
	XmppJid* _tmp1_;
	XmppJid* _tmp2_;
	self = _data34_->self;
	g_return_if_fail (stream != NULL);
	g_return_if_fail (presence != NULL);
	_tmp0_ = xmpp_stanza_get_from ((XmppStanza*) presence);
	_tmp1_ = _tmp0_;
	_tmp2_ = _tmp1_;
	dino_presence_manager_on_received_unavailable (self, _data34_->account, _tmp2_);
	_xmpp_jid_unref0 (_tmp2_);
}

static void
___lambda66__xmpp_presence_module_received_unavailable (XmppPresenceModule* _sender,
                                                        XmppXmppStream* stream,
                                                        XmppPresenceStanza* presence,
                                                        gpointer self)
{
	__lambda66_ (self, stream, presence);
}

static void
__lambda67_ (Block34Data* _data34_,
             XmppXmppStream* stream,
             XmppJid* jid)
{
	DinoPresenceManager* self;
	GeeList* _tmp0_;
	self = _data34_->self;
	g_return_if_fail (stream != NULL);
	g_return_if_fail (jid != NULL);
	_tmp0_ = self->priv->subscription_requests;
	if (!gee_collection_contains ((GeeCollection*) _tmp0_, jid)) {
		GeeList* _tmp1_;
		_tmp1_ = self->priv->subscription_requests;
		gee_collection_add ((GeeCollection*) _tmp1_, jid);
	}
	g_signal_emit (self, dino_presence_manager_signals[DINO_PRESENCE_MANAGER_RECEIVED_SUBSCRIPTION_REQUEST_SIGNAL], 0, jid, _data34_->account);
}

static void
___lambda67__xmpp_presence_module_received_subscription_request (XmppPresenceModule* _sender,
                                                                 XmppXmppStream* stream,
                                                                 XmppJid* jid,
                                                                 gpointer self)
{
	__lambda67_ (self, stream, jid);
}

static void
__lambda68_ (Block34Data* _data34_,
             XmppXmppStream* stream,
             XmppJid* jid)
{
	DinoPresenceManager* self;
	self = _data34_->self;
	g_return_if_fail (stream != NULL);
	g_return_if_fail (jid != NULL);
	g_signal_emit (self, dino_presence_manager_signals[DINO_PRESENCE_MANAGER_RECEIVED_SUBSCRIPTION_APPROVAL_SIGNAL], 0, jid, _data34_->account);
}

static void
___lambda68__xmpp_presence_module_received_subscription_approval (XmppPresenceModule* _sender,
                                                                  XmppXmppStream* stream,
                                                                  XmppJid* jid,
                                                                  gpointer self)
{
	__lambda68_ (self, stream, jid);
}

static void
dino_presence_manager_on_account_added (DinoPresenceManager* self,
                                        DinoEntitiesAccount* account)
{
	Block34Data* _data34_;
	DinoEntitiesAccount* _tmp0_;
	DinoStreamInteractor* _tmp1_;
	DinoModuleManager* _tmp2_;
	XmppModuleIdentity* _tmp3_;
	gpointer _tmp4_;
	XmppPresenceModule* _tmp5_;
	DinoStreamInteractor* _tmp6_;
	DinoModuleManager* _tmp7_;
	XmppModuleIdentity* _tmp8_;
	gpointer _tmp9_;
	XmppPresenceModule* _tmp10_;
	DinoStreamInteractor* _tmp11_;
	DinoModuleManager* _tmp12_;
	XmppModuleIdentity* _tmp13_;
	gpointer _tmp14_;
	XmppPresenceModule* _tmp15_;
	DinoStreamInteractor* _tmp16_;
	DinoModuleManager* _tmp17_;
	XmppModuleIdentity* _tmp18_;
	gpointer _tmp19_;
	XmppPresenceModule* _tmp20_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (account != NULL);
	_data34_ = g_slice_new0 (Block34Data);
	_data34_->_ref_count_ = 1;
	_data34_->self = g_object_ref (self);
	_tmp0_ = _g_object_ref0 (account);
	_g_object_unref0 (_data34_->account);
	_data34_->account = _tmp0_;
	_tmp1_ = self->priv->stream_interactor;
	_tmp2_ = _tmp1_->module_manager;
	_tmp3_ = xmpp_presence_module_IDENTITY;
	_tmp4_ = dino_module_manager_get_module (_tmp2_, XMPP_PRESENCE_TYPE_MODULE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _data34_->account, _tmp3_);
	_tmp5_ = (XmppPresenceModule*) _tmp4_;
	g_signal_connect_data (_tmp5_, "received-available-show", (GCallback) ___lambda65__xmpp_presence_module_received_available_show, block34_data_ref (_data34_), (GClosureNotify) block34_data_unref, 0);
	_g_object_unref0 (_tmp5_);
	_tmp6_ = self->priv->stream_interactor;
	_tmp7_ = _tmp6_->module_manager;
	_tmp8_ = xmpp_presence_module_IDENTITY;
	_tmp9_ = dino_module_manager_get_module (_tmp7_, XMPP_PRESENCE_TYPE_MODULE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _data34_->account, _tmp8_);
	_tmp10_ = (XmppPresenceModule*) _tmp9_;
	g_signal_connect_data (_tmp10_, "received-unavailable", (GCallback) ___lambda66__xmpp_presence_module_received_unavailable, block34_data_ref (_data34_), (GClosureNotify) block34_data_unref, 0);
	_g_object_unref0 (_tmp10_);
	_tmp11_ = self->priv->stream_interactor;
	_tmp12_ = _tmp11_->module_manager;
	_tmp13_ = xmpp_presence_module_IDENTITY;
	_tmp14_ = dino_module_manager_get_module (_tmp12_, XMPP_PRESENCE_TYPE_MODULE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _data34_->account, _tmp13_);
	_tmp15_ = (XmppPresenceModule*) _tmp14_;
	g_signal_connect_data (_tmp15_, "received-subscription-request", (GCallback) ___lambda67__xmpp_presence_module_received_subscription_request, block34_data_ref (_data34_), (GClosureNotify) block34_data_unref, 0);
	_g_object_unref0 (_tmp15_);
	_tmp16_ = self->priv->stream_interactor;
	_tmp17_ = _tmp16_->module_manager;
	_tmp18_ = xmpp_presence_module_IDENTITY;
	_tmp19_ = dino_module_manager_get_module (_tmp17_, XMPP_PRESENCE_TYPE_MODULE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _data34_->account, _tmp18_);
	_tmp20_ = (XmppPresenceModule*) _tmp19_;
	g_signal_connect_data (_tmp20_, "received-subscription-approval", (GCallback) ___lambda68__xmpp_presence_module_received_subscription_approval, block34_data_ref (_data34_), (GClosureNotify) block34_data_unref, 0);
	_g_object_unref0 (_tmp20_);
	block34_data_unref (_data34_);
	_data34_ = NULL;
}

static void
dino_presence_manager_on_received_available_show (DinoPresenceManager* self,
                                                  DinoEntitiesAccount* account,
                                                  XmppJid* jid,
                                                  const gchar* show)
{
	GError* _inner_error0_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (account != NULL);
	g_return_if_fail (jid != NULL);
	g_return_if_fail (show != NULL);
	{
		GeeHashMap* _tmp0_;
		_tmp0_ = self->priv->resources;
		g_rec_mutex_lock (&self->priv->__lock_resources);
		{
			GeeHashMap* _tmp1_;
			GeeHashMap* _tmp5_;
			gpointer _tmp6_;
			GeeArrayList* _tmp7_;
			gboolean _tmp8_;
			_tmp1_ = self->priv->resources;
			if (!gee_abstract_map_has_key ((GeeAbstractMap*) _tmp1_, jid)) {
				GeeHashMap* _tmp2_;
				GeeArrayList* _tmp3_;
				GeeArrayList* _tmp4_;
				_tmp2_ = self->priv->resources;
				_tmp3_ = gee_array_list_new (XMPP_TYPE_JID, (GBoxedCopyFunc) xmpp_jid_ref, (GDestroyNotify) xmpp_jid_unref, _xmpp_jid_equals_func_gee_equal_data_func, NULL, NULL);
				_tmp4_ = _tmp3_;
				gee_abstract_map_set ((GeeAbstractMap*) _tmp2_, jid, _tmp4_);
				_g_object_unref0 (_tmp4_);
			}
			_tmp5_ = self->priv->resources;
			_tmp6_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp5_, jid);
			_tmp7_ = (GeeArrayList*) _tmp6_;
			_tmp8_ = !gee_abstract_collection_contains ((GeeAbstractCollection*) _tmp7_, jid);
			_g_object_unref0 (_tmp7_);
			if (_tmp8_) {
				GeeHashMap* _tmp9_;
				gpointer _tmp10_;
				GeeArrayList* _tmp11_;
				_tmp9_ = self->priv->resources;
				_tmp10_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp9_, jid);
				_tmp11_ = (GeeArrayList*) _tmp10_;
				gee_abstract_collection_add ((GeeAbstractCollection*) _tmp11_, jid);
				_g_object_unref0 (_tmp11_);
			}
		}
		__finally0:
		{
			GeeHashMap* _tmp12_;
			_tmp12_ = self->priv->resources;
			g_rec_mutex_unlock (&self->priv->__lock_resources);
		}
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			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;
		}
	}
	g_signal_emit (self, dino_presence_manager_signals[DINO_PRESENCE_MANAGER_SHOW_RECEIVED_SIGNAL], 0, jid, account);
}

static void
dino_presence_manager_on_received_unavailable (DinoPresenceManager* self,
                                               DinoEntitiesAccount* account,
                                               XmppJid* jid)
{
	GError* _inner_error0_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (account != NULL);
	g_return_if_fail (jid != NULL);
	{
		GeeHashMap* _tmp0_;
		_tmp0_ = self->priv->resources;
		g_rec_mutex_lock (&self->priv->__lock_resources);
		{
			GeeHashMap* _tmp1_;
			_tmp1_ = self->priv->resources;
			if (gee_abstract_map_has_key ((GeeAbstractMap*) _tmp1_, jid)) {
				GeeHashMap* _tmp2_;
				gpointer _tmp3_;
				GeeArrayList* _tmp4_;
				gboolean _tmp5_ = FALSE;
				GeeHashMap* _tmp6_;
				gpointer _tmp7_;
				GeeArrayList* _tmp8_;
				gint _tmp9_;
				gint _tmp10_;
				gboolean _tmp11_;
				_tmp2_ = self->priv->resources;
				_tmp3_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp2_, jid);
				_tmp4_ = (GeeArrayList*) _tmp3_;
				gee_abstract_collection_remove ((GeeAbstractCollection*) _tmp4_, jid);
				_g_object_unref0 (_tmp4_);
				_tmp6_ = self->priv->resources;
				_tmp7_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp6_, jid);
				_tmp8_ = (GeeArrayList*) _tmp7_;
				_tmp9_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp8_);
				_tmp10_ = _tmp9_;
				_tmp11_ = _tmp10_ == 0;
				_g_object_unref0 (_tmp8_);
				if (_tmp11_) {
					_tmp5_ = TRUE;
				} else {
					_tmp5_ = xmpp_jid_is_bare (jid);
				}
				if (_tmp5_) {
					GeeHashMap* _tmp12_;
					_tmp12_ = self->priv->resources;
					gee_abstract_map_unset ((GeeAbstractMap*) _tmp12_, jid, NULL);
				}
			}
		}
		__finally0:
		{
			GeeHashMap* _tmp13_;
			_tmp13_ = self->priv->resources;
			g_rec_mutex_unlock (&self->priv->__lock_resources);
		}
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			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;
		}
	}
	g_signal_emit (self, dino_presence_manager_signals[DINO_PRESENCE_MANAGER_RECEIVED_OFFLINE_PRESENCE_SIGNAL], 0, jid, account);
}

static const gchar*
dino_presence_manager_real_get_id (DinoStreamInteractionModule* base)
{
	const gchar* result;
	DinoPresenceManager* self;
	DinoModuleIdentity* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	self = (DinoPresenceManager*) base;
	_tmp0_ = dino_presence_manager_IDENTITY;
	_tmp1_ = dino_module_identity_get_id (_tmp0_);
	_tmp2_ = _tmp1_;
	result = _tmp2_;
	return result;
}

static void
g_cclosure_user_marshal_VOID__XMPP_JID_OBJECT (GClosure * closure,
                                               GValue * return_value,
                                               guint n_param_values,
                                               const GValue * param_values,
                                               gpointer invocation_hint,
                                               gpointer marshal_data)
{
	typedef void (*GMarshalFunc_VOID__XMPP_JID_OBJECT) (gpointer data1, gpointer arg_1, gpointer arg_2, gpointer data2);
	register GMarshalFunc_VOID__XMPP_JID_OBJECT callback;
	register GCClosure * cc;
	register gpointer data1;
	register gpointer data2;
	cc = (GCClosure *) closure;
	g_return_if_fail (n_param_values == 3);
	if (G_CCLOSURE_SWAP_DATA (closure)) {
		data1 = closure->data;
		data2 = param_values->data[0].v_pointer;
	} else {
		data1 = param_values->data[0].v_pointer;
		data2 = closure->data;
	}
	callback = (GMarshalFunc_VOID__XMPP_JID_OBJECT) (marshal_data ? marshal_data : cc->callback);
	callback (data1, xmpp_value_get_jid (param_values + 1), g_value_get_object (param_values + 2), data2);
}

static void
dino_presence_manager_class_init (DinoPresenceManagerClass * klass,
                                  gpointer klass_data)
{
	DinoModuleIdentity* _tmp0_;
	dino_presence_manager_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &DinoPresenceManager_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_dino_presence_manager_get_property;
	G_OBJECT_CLASS (klass)->finalize = dino_presence_manager_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), DINO_PRESENCE_MANAGER_ID_PROPERTY, dino_presence_manager_properties[DINO_PRESENCE_MANAGER_ID_PROPERTY] = g_param_spec_string ("id", "id", "id", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	dino_presence_manager_signals[DINO_PRESENCE_MANAGER_SHOW_RECEIVED_SIGNAL] = g_signal_new ("show-received", DINO_TYPE_PRESENCE_MANAGER, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_user_marshal_VOID__XMPP_JID_OBJECT, G_TYPE_NONE, 2, XMPP_TYPE_JID, DINO_ENTITIES_TYPE_ACCOUNT);
	dino_presence_manager_signals[DINO_PRESENCE_MANAGER_RECEIVED_OFFLINE_PRESENCE_SIGNAL] = g_signal_new ("received-offline-presence", DINO_TYPE_PRESENCE_MANAGER, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_user_marshal_VOID__XMPP_JID_OBJECT, G_TYPE_NONE, 2, XMPP_TYPE_JID, DINO_ENTITIES_TYPE_ACCOUNT);
	dino_presence_manager_signals[DINO_PRESENCE_MANAGER_RECEIVED_SUBSCRIPTION_REQUEST_SIGNAL] = g_signal_new ("received-subscription-request", DINO_TYPE_PRESENCE_MANAGER, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_user_marshal_VOID__XMPP_JID_OBJECT, G_TYPE_NONE, 2, XMPP_TYPE_JID, DINO_ENTITIES_TYPE_ACCOUNT);
	dino_presence_manager_signals[DINO_PRESENCE_MANAGER_RECEIVED_SUBSCRIPTION_APPROVAL_SIGNAL] = g_signal_new ("received-subscription-approval", DINO_TYPE_PRESENCE_MANAGER, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_user_marshal_VOID__XMPP_JID_OBJECT, G_TYPE_NONE, 2, XMPP_TYPE_JID, DINO_ENTITIES_TYPE_ACCOUNT);
	_tmp0_ = dino_module_identity_new (DINO_TYPE_PRESENCE_MANAGER, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, "presence_manager");
	dino_presence_manager_IDENTITY = _tmp0_;
}

static void
dino_presence_manager_dino_stream_interaction_module_interface_init (DinoStreamInteractionModuleIface * iface,
                                                                     gpointer iface_data)
{
	dino_presence_manager_dino_stream_interaction_module_parent_iface = g_type_interface_peek_parent (iface);
	iface->get_id = dino_presence_manager_real_get_id;
}

static void
dino_presence_manager_instance_init (DinoPresenceManager * self,
                                     gpointer klass)
{
	GeeHashMap* _tmp0_;
	GeeArrayList* _tmp1_;
	self->priv = dino_presence_manager_get_instance_private (self);
	g_rec_mutex_init (&self->priv->__lock_resources);
	_tmp0_ = gee_hash_map_new (XMPP_TYPE_JID, (GBoxedCopyFunc) xmpp_jid_ref, (GDestroyNotify) xmpp_jid_unref, GEE_TYPE_ARRAY_LIST, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _xmpp_jid_hash_bare_func_gee_hash_data_func, NULL, NULL, _xmpp_jid_equals_bare_func_gee_equal_data_func, NULL, NULL, NULL, NULL, NULL);
	self->priv->resources = _tmp0_;
	_tmp1_ = gee_array_list_new (XMPP_TYPE_JID, (GBoxedCopyFunc) xmpp_jid_ref, (GDestroyNotify) xmpp_jid_unref, _xmpp_jid_equals_func_gee_equal_data_func, NULL, NULL);
	self->priv->subscription_requests = (GeeList*) _tmp1_;
}

static void
dino_presence_manager_finalize (GObject * obj)
{
	DinoPresenceManager * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, DINO_TYPE_PRESENCE_MANAGER, DinoPresenceManager);
	_g_object_unref0 (self->priv->stream_interactor);
	g_rec_mutex_clear (&self->priv->__lock_resources);
	_g_object_unref0 (self->priv->resources);
	_g_object_unref0 (self->priv->subscription_requests);
	G_OBJECT_CLASS (dino_presence_manager_parent_class)->finalize (obj);
}

static GType
dino_presence_manager_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (DinoPresenceManagerClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) dino_presence_manager_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DinoPresenceManager), 0, (GInstanceInitFunc) dino_presence_manager_instance_init, NULL };
	static const GInterfaceInfo dino_stream_interaction_module_info = { (GInterfaceInitFunc) dino_presence_manager_dino_stream_interaction_module_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	GType dino_presence_manager_type_id;
	dino_presence_manager_type_id = g_type_register_static (G_TYPE_OBJECT, "DinoPresenceManager", &g_define_type_info, 0);
	g_type_add_interface_static (dino_presence_manager_type_id, DINO_TYPE_STREAM_INTERACTION_MODULE, &dino_stream_interaction_module_info);
	DinoPresenceManager_private_offset = g_type_add_instance_private (dino_presence_manager_type_id, sizeof (DinoPresenceManagerPrivate));
	return dino_presence_manager_type_id;
}

GType
dino_presence_manager_get_type (void)
{
	static volatile gsize dino_presence_manager_type_id__once = 0;
	if (g_once_init_enter (&dino_presence_manager_type_id__once)) {
		GType dino_presence_manager_type_id;
		dino_presence_manager_type_id = dino_presence_manager_get_type_once ();
		g_once_init_leave (&dino_presence_manager_type_id__once, dino_presence_manager_type_id);
	}
	return dino_presence_manager_type_id__once;
}

static void
_vala_dino_presence_manager_get_property (GObject * object,
                                          guint property_id,
                                          GValue * value,
                                          GParamSpec * pspec)
{
	DinoPresenceManager * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, DINO_TYPE_PRESENCE_MANAGER, DinoPresenceManager);
	switch (property_id) {
		case DINO_PRESENCE_MANAGER_ID_PROPERTY:
		g_value_set_string (value, dino_stream_interaction_module_get_id ((DinoStreamInteractionModule*) self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

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

