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

/*
 * Copyright (C) 2009-2012 Michael 'Mickey' Lauer <mlauer@vanille-media.de>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.

 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.

 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
 *
 */

#include <glib.h>
#include <glib-object.h>


#define FSO_FRAMEWORK_TYPE_ABSTRACT_WORKER_QUEUE (fso_framework_abstract_worker_queue_get_type ())
#define FSO_FRAMEWORK_ABSTRACT_WORKER_QUEUE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), FSO_FRAMEWORK_TYPE_ABSTRACT_WORKER_QUEUE, FsoFrameworkAbstractWorkerQueue))
#define FSO_FRAMEWORK_IS_ABSTRACT_WORKER_QUEUE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), FSO_FRAMEWORK_TYPE_ABSTRACT_WORKER_QUEUE))
#define FSO_FRAMEWORK_ABSTRACT_WORKER_QUEUE_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), FSO_FRAMEWORK_TYPE_ABSTRACT_WORKER_QUEUE, FsoFrameworkAbstractWorkerQueueIface))

typedef struct _FsoFrameworkAbstractWorkerQueue FsoFrameworkAbstractWorkerQueue;
typedef struct _FsoFrameworkAbstractWorkerQueueIface FsoFrameworkAbstractWorkerQueueIface;

#define FSO_FRAMEWORK_TYPE_ASYNC_WORKER_QUEUE (fso_framework_async_worker_queue_get_type ())
#define FSO_FRAMEWORK_ASYNC_WORKER_QUEUE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), FSO_FRAMEWORK_TYPE_ASYNC_WORKER_QUEUE, FsoFrameworkAsyncWorkerQueue))
#define FSO_FRAMEWORK_ASYNC_WORKER_QUEUE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), FSO_FRAMEWORK_TYPE_ASYNC_WORKER_QUEUE, FsoFrameworkAsyncWorkerQueueClass))
#define FSO_FRAMEWORK_IS_ASYNC_WORKER_QUEUE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), FSO_FRAMEWORK_TYPE_ASYNC_WORKER_QUEUE))
#define FSO_FRAMEWORK_IS_ASYNC_WORKER_QUEUE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), FSO_FRAMEWORK_TYPE_ASYNC_WORKER_QUEUE))
#define FSO_FRAMEWORK_ASYNC_WORKER_QUEUE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), FSO_FRAMEWORK_TYPE_ASYNC_WORKER_QUEUE, FsoFrameworkAsyncWorkerQueueClass))

typedef struct _FsoFrameworkAsyncWorkerQueue FsoFrameworkAsyncWorkerQueue;
typedef struct _FsoFrameworkAsyncWorkerQueueClass FsoFrameworkAsyncWorkerQueueClass;
typedef struct _FsoFrameworkAsyncWorkerQueuePrivate FsoFrameworkAsyncWorkerQueuePrivate;
#define _g_queue_free0(var) ((var == NULL) ? NULL : (var = (g_queue_free (var), NULL)))

typedef void (*FsoFrameworkAbstractWorkerQueueWorkerFunc) (gconstpointer element, void* user_data);
struct _FsoFrameworkAbstractWorkerQueueIface {
	GTypeInterface parent_iface;
	void (*setDelegate) (FsoFrameworkAbstractWorkerQueue* self, FsoFrameworkAbstractWorkerQueueWorkerFunc worker, void* worker_target);
	void (*enqueue) (FsoFrameworkAbstractWorkerQueue* self, gconstpointer element);
	void (*trigger) (FsoFrameworkAbstractWorkerQueue* self);
};

struct _FsoFrameworkAsyncWorkerQueue {
	GObject parent_instance;
	FsoFrameworkAsyncWorkerQueuePrivate * priv;
	GQueue* q;
	FsoFrameworkAbstractWorkerQueueWorkerFunc worker;
	gpointer worker_target;
	GDestroyNotify worker_target_destroy_notify;
};

struct _FsoFrameworkAsyncWorkerQueueClass {
	GObjectClass parent_class;
};

struct _FsoFrameworkAsyncWorkerQueuePrivate {
	GType t_type;
	GBoxedCopyFunc t_dup_func;
	GDestroyNotify t_destroy_func;
	guint watch;
};


static gpointer fso_framework_async_worker_queue_parent_class = NULL;
static FsoFrameworkAbstractWorkerQueueIface* fso_framework_async_worker_queue_fso_framework_abstract_worker_queue_parent_iface = NULL;

GType fso_framework_abstract_worker_queue_get_type (void) G_GNUC_CONST;
void fso_framework_abstract_worker_queue_setDelegate (FsoFrameworkAbstractWorkerQueue* self, FsoFrameworkAbstractWorkerQueueWorkerFunc worker, void* worker_target);
void fso_framework_abstract_worker_queue_enqueue (FsoFrameworkAbstractWorkerQueue* self, gconstpointer element);
void fso_framework_abstract_worker_queue_trigger (FsoFrameworkAbstractWorkerQueue* self);
GType fso_framework_async_worker_queue_get_type (void) G_GNUC_CONST;
#define FSO_FRAMEWORK_ASYNC_WORKER_QUEUE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), FSO_FRAMEWORK_TYPE_ASYNC_WORKER_QUEUE, FsoFrameworkAsyncWorkerQueuePrivate))
enum  {
	FSO_FRAMEWORK_ASYNC_WORKER_QUEUE_DUMMY_PROPERTY,
	FSO_FRAMEWORK_ASYNC_WORKER_QUEUE_T_TYPE,
	FSO_FRAMEWORK_ASYNC_WORKER_QUEUE_T_DUP_FUNC,
	FSO_FRAMEWORK_ASYNC_WORKER_QUEUE_T_DESTROY_FUNC
};
gboolean _fso_framework_async_worker_queue_onIdle (FsoFrameworkAsyncWorkerQueue* self);
static void fso_framework_async_worker_queue_real_setDelegate (FsoFrameworkAbstractWorkerQueue* base, FsoFrameworkAbstractWorkerQueueWorkerFunc worker, void* worker_target);
static void fso_framework_async_worker_queue_real_enqueue (FsoFrameworkAbstractWorkerQueue* base, gconstpointer element);
static void fso_framework_async_worker_queue_real_trigger (FsoFrameworkAbstractWorkerQueue* base);
static gboolean __fso_framework_async_worker_queue_onIdle_gsource_func (gpointer self);
FsoFrameworkAsyncWorkerQueue* fso_framework_async_worker_queue_new (GType t_type, GBoxedCopyFunc t_dup_func, GDestroyNotify t_destroy_func);
FsoFrameworkAsyncWorkerQueue* fso_framework_async_worker_queue_construct (GType object_type, GType t_type, GBoxedCopyFunc t_dup_func, GDestroyNotify t_destroy_func);
static GObject * fso_framework_async_worker_queue_constructor (GType type, guint n_construct_properties, GObjectConstructParam * construct_properties);
static void fso_framework_async_worker_queue_finalize (GObject* obj);
static void _vala_fso_framework_async_worker_queue_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec);
static void _vala_fso_framework_async_worker_queue_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec);


void fso_framework_abstract_worker_queue_setDelegate (FsoFrameworkAbstractWorkerQueue* self, FsoFrameworkAbstractWorkerQueueWorkerFunc worker, void* worker_target) {
	g_return_if_fail (self != NULL);
	FSO_FRAMEWORK_ABSTRACT_WORKER_QUEUE_GET_INTERFACE (self)->setDelegate (self, worker, worker_target);
}


void fso_framework_abstract_worker_queue_enqueue (FsoFrameworkAbstractWorkerQueue* self, gconstpointer element) {
	g_return_if_fail (self != NULL);
	FSO_FRAMEWORK_ABSTRACT_WORKER_QUEUE_GET_INTERFACE (self)->enqueue (self, element);
}


void fso_framework_abstract_worker_queue_trigger (FsoFrameworkAbstractWorkerQueue* self) {
	g_return_if_fail (self != NULL);
	FSO_FRAMEWORK_ABSTRACT_WORKER_QUEUE_GET_INTERFACE (self)->trigger (self);
}


static void fso_framework_abstract_worker_queue_base_init (FsoFrameworkAbstractWorkerQueueIface * iface) {
	static gboolean initialized = FALSE;
	if (!initialized) {
		initialized = TRUE;
	}
}


/**
 * @class FsoFramework.AbstractWorkerQueue
 **/
GType fso_framework_abstract_worker_queue_get_type (void) {
	static volatile gsize fso_framework_abstract_worker_queue_type_id__volatile = 0;
	if (g_once_init_enter (&fso_framework_abstract_worker_queue_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (FsoFrameworkAbstractWorkerQueueIface), (GBaseInitFunc) fso_framework_abstract_worker_queue_base_init, (GBaseFinalizeFunc) NULL, (GClassInitFunc) NULL, (GClassFinalizeFunc) NULL, NULL, 0, 0, (GInstanceInitFunc) NULL, NULL };
		GType fso_framework_abstract_worker_queue_type_id;
		fso_framework_abstract_worker_queue_type_id = g_type_register_static (G_TYPE_INTERFACE, "FsoFrameworkAbstractWorkerQueue", &g_define_type_info, 0);
		g_type_interface_add_prerequisite (fso_framework_abstract_worker_queue_type_id, G_TYPE_OBJECT);
		g_once_init_leave (&fso_framework_abstract_worker_queue_type_id__volatile, fso_framework_abstract_worker_queue_type_id);
	}
	return fso_framework_abstract_worker_queue_type_id__volatile;
}


gboolean _fso_framework_async_worker_queue_onIdle (FsoFrameworkAsyncWorkerQueue* self) {
	gboolean result = FALSE;
	FsoFrameworkAbstractWorkerQueueWorkerFunc _tmp0_;
	void* _tmp0__target;
	FsoFrameworkAbstractWorkerQueueWorkerFunc _tmp1_;
	void* _tmp1__target;
	GQueue* _tmp2_;
	gpointer _tmp3_ = NULL;
	gpointer _tmp4_;
	g_return_val_if_fail (self != NULL, FALSE);
	_tmp0_ = self->worker;
	_tmp0__target = self->worker_target;
	g_assert (_tmp0_ != NULL);
	_tmp1_ = self->worker;
	_tmp1__target = self->worker_target;
	_tmp2_ = self->q;
	_tmp3_ = g_queue_pop_tail (_tmp2_);
	_tmp4_ = _tmp3_;
	_tmp1_ (_tmp4_, _tmp1__target);
	((_tmp4_ == NULL) || (self->priv->t_destroy_func == NULL)) ? NULL : (_tmp4_ = (self->priv->t_destroy_func (_tmp4_), NULL));
	self->priv->watch = (guint) 0;
	result = FALSE;
	return result;
}


static void fso_framework_async_worker_queue_real_setDelegate (FsoFrameworkAbstractWorkerQueue* base, FsoFrameworkAbstractWorkerQueueWorkerFunc worker, void* worker_target) {
	FsoFrameworkAsyncWorkerQueue * self;
	FsoFrameworkAbstractWorkerQueueWorkerFunc _tmp0_;
	void* _tmp0__target;
	self = (FsoFrameworkAsyncWorkerQueue*) base;
	_tmp0_ = worker;
	_tmp0__target = worker_target;
	(self->worker_target_destroy_notify == NULL) ? NULL : (self->worker_target_destroy_notify (self->worker_target), NULL);
	self->worker = NULL;
	self->worker_target = NULL;
	self->worker_target_destroy_notify = NULL;
	self->worker = _tmp0_;
	self->worker_target = _tmp0__target;
	self->worker_target_destroy_notify = NULL;
	fso_framework_abstract_worker_queue_trigger ((FsoFrameworkAbstractWorkerQueue*) self);
}


static void fso_framework_async_worker_queue_real_enqueue (FsoFrameworkAbstractWorkerQueue* base, gconstpointer element) {
	FsoFrameworkAsyncWorkerQueue * self;
	GQueue* _tmp0_;
	guint _tmp1_;
	gboolean retrigger;
	GQueue* _tmp2_;
	gconstpointer _tmp3_;
	gpointer _tmp4_;
	gboolean _tmp5_ = FALSE;
	gboolean _tmp6_;
	gboolean _tmp8_;
	self = (FsoFrameworkAsyncWorkerQueue*) base;
	_tmp0_ = self->q;
	_tmp1_ = _tmp0_->length;
	retrigger = _tmp1_ == ((guint) 0);
	_tmp2_ = self->q;
	_tmp3_ = element;
	_tmp4_ = ((_tmp3_ != NULL) && (self->priv->t_dup_func != NULL)) ? self->priv->t_dup_func ((gpointer) _tmp3_) : ((gpointer) _tmp3_);
	g_queue_push_head (_tmp2_, _tmp4_);
	_tmp6_ = retrigger;
	if (_tmp6_) {
		FsoFrameworkAbstractWorkerQueueWorkerFunc _tmp7_;
		void* _tmp7__target;
		_tmp7_ = self->worker;
		_tmp7__target = self->worker_target;
		_tmp5_ = _tmp7_ != NULL;
	} else {
		_tmp5_ = FALSE;
	}
	_tmp8_ = _tmp5_;
	if (_tmp8_) {
		fso_framework_abstract_worker_queue_trigger ((FsoFrameworkAbstractWorkerQueue*) self);
	}
}


static gboolean __fso_framework_async_worker_queue_onIdle_gsource_func (gpointer self) {
	gboolean result;
	result = _fso_framework_async_worker_queue_onIdle (self);
	return result;
}


static void fso_framework_async_worker_queue_real_trigger (FsoFrameworkAbstractWorkerQueue* base) {
	FsoFrameworkAsyncWorkerQueue * self;
	GQueue* _tmp0_;
	guint _tmp1_;
	FsoFrameworkAbstractWorkerQueueWorkerFunc _tmp2_;
	void* _tmp2__target;
	guint _tmp3_ = 0U;
	self = (FsoFrameworkAsyncWorkerQueue*) base;
	_tmp0_ = self->q;
	_tmp1_ = _tmp0_->length;
	g_assert (_tmp1_ > ((guint) 0));
	_tmp2_ = self->worker;
	_tmp2__target = self->worker_target;
	g_assert (_tmp2_ != NULL);
	_tmp3_ = g_idle_add_full (G_PRIORITY_DEFAULT_IDLE, __fso_framework_async_worker_queue_onIdle_gsource_func, g_object_ref (self), g_object_unref);
	self->priv->watch = _tmp3_;
}


FsoFrameworkAsyncWorkerQueue* fso_framework_async_worker_queue_construct (GType object_type, GType t_type, GBoxedCopyFunc t_dup_func, GDestroyNotify t_destroy_func) {
	FsoFrameworkAsyncWorkerQueue * self = NULL;
	self = (FsoFrameworkAsyncWorkerQueue*) g_object_new (object_type, NULL);
	self->priv->t_type = t_type;
	self->priv->t_dup_func = t_dup_func;
	self->priv->t_destroy_func = t_destroy_func;
	return self;
}


FsoFrameworkAsyncWorkerQueue* fso_framework_async_worker_queue_new (GType t_type, GBoxedCopyFunc t_dup_func, GDestroyNotify t_destroy_func) {
	return fso_framework_async_worker_queue_construct (FSO_FRAMEWORK_TYPE_ASYNC_WORKER_QUEUE, t_type, t_dup_func, t_destroy_func);
}


static GObject * fso_framework_async_worker_queue_constructor (GType type, guint n_construct_properties, GObjectConstructParam * construct_properties) {
	GObject * obj;
	GObjectClass * parent_class;
	FsoFrameworkAsyncWorkerQueue * self;
	GQueue* _tmp0_;
	parent_class = G_OBJECT_CLASS (fso_framework_async_worker_queue_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = FSO_FRAMEWORK_ASYNC_WORKER_QUEUE (obj);
	_tmp0_ = g_queue_new ();
	_g_queue_free0 (self->q);
	self->q = _tmp0_;
	return obj;
}


static void fso_framework_async_worker_queue_class_init (FsoFrameworkAsyncWorkerQueueClass * klass) {
	fso_framework_async_worker_queue_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (FsoFrameworkAsyncWorkerQueuePrivate));
	G_OBJECT_CLASS (klass)->get_property = _vala_fso_framework_async_worker_queue_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_fso_framework_async_worker_queue_set_property;
	G_OBJECT_CLASS (klass)->constructor = fso_framework_async_worker_queue_constructor;
	G_OBJECT_CLASS (klass)->finalize = fso_framework_async_worker_queue_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), FSO_FRAMEWORK_ASYNC_WORKER_QUEUE_T_TYPE, g_param_spec_gtype ("t-type", "type", "type", G_TYPE_NONE, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
	g_object_class_install_property (G_OBJECT_CLASS (klass), FSO_FRAMEWORK_ASYNC_WORKER_QUEUE_T_DUP_FUNC, g_param_spec_pointer ("t-dup-func", "dup func", "dup func", G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
	g_object_class_install_property (G_OBJECT_CLASS (klass), FSO_FRAMEWORK_ASYNC_WORKER_QUEUE_T_DESTROY_FUNC, g_param_spec_pointer ("t-destroy-func", "destroy func", "destroy func", G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
}


static void fso_framework_async_worker_queue_fso_framework_abstract_worker_queue_interface_init (FsoFrameworkAbstractWorkerQueueIface * iface) {
	fso_framework_async_worker_queue_fso_framework_abstract_worker_queue_parent_iface = g_type_interface_peek_parent (iface);
	iface->setDelegate = (void (*)(FsoFrameworkAbstractWorkerQueue*, FsoFrameworkAbstractWorkerQueueWorkerFunc, void*)) fso_framework_async_worker_queue_real_setDelegate;
	iface->enqueue = (void (*)(FsoFrameworkAbstractWorkerQueue*, gconstpointer)) fso_framework_async_worker_queue_real_enqueue;
	iface->trigger = (void (*)(FsoFrameworkAbstractWorkerQueue*)) fso_framework_async_worker_queue_real_trigger;
}


static void fso_framework_async_worker_queue_instance_init (FsoFrameworkAsyncWorkerQueue * self) {
	self->priv = FSO_FRAMEWORK_ASYNC_WORKER_QUEUE_GET_PRIVATE (self);
}


static void fso_framework_async_worker_queue_finalize (GObject* obj) {
	FsoFrameworkAsyncWorkerQueue * self;
	self = FSO_FRAMEWORK_ASYNC_WORKER_QUEUE (obj);
	_g_queue_free0 (self->q);
	(self->worker_target_destroy_notify == NULL) ? NULL : (self->worker_target_destroy_notify (self->worker_target), NULL);
	self->worker = NULL;
	self->worker_target = NULL;
	self->worker_target_destroy_notify = NULL;
	G_OBJECT_CLASS (fso_framework_async_worker_queue_parent_class)->finalize (obj);
}


/**
 * @class FsoFramework.AsyncWorkerQueue
 **/
GType fso_framework_async_worker_queue_get_type (void) {
	static volatile gsize fso_framework_async_worker_queue_type_id__volatile = 0;
	if (g_once_init_enter (&fso_framework_async_worker_queue_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (FsoFrameworkAsyncWorkerQueueClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) fso_framework_async_worker_queue_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (FsoFrameworkAsyncWorkerQueue), 0, (GInstanceInitFunc) fso_framework_async_worker_queue_instance_init, NULL };
		static const GInterfaceInfo fso_framework_abstract_worker_queue_info = { (GInterfaceInitFunc) fso_framework_async_worker_queue_fso_framework_abstract_worker_queue_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
		GType fso_framework_async_worker_queue_type_id;
		fso_framework_async_worker_queue_type_id = g_type_register_static (G_TYPE_OBJECT, "FsoFrameworkAsyncWorkerQueue", &g_define_type_info, 0);
		g_type_add_interface_static (fso_framework_async_worker_queue_type_id, FSO_FRAMEWORK_TYPE_ABSTRACT_WORKER_QUEUE, &fso_framework_abstract_worker_queue_info);
		g_once_init_leave (&fso_framework_async_worker_queue_type_id__volatile, fso_framework_async_worker_queue_type_id);
	}
	return fso_framework_async_worker_queue_type_id__volatile;
}


static void _vala_fso_framework_async_worker_queue_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec) {
	FsoFrameworkAsyncWorkerQueue * self;
	self = FSO_FRAMEWORK_ASYNC_WORKER_QUEUE (object);
	switch (property_id) {
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}


static void _vala_fso_framework_async_worker_queue_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec) {
	FsoFrameworkAsyncWorkerQueue * self;
	self = FSO_FRAMEWORK_ASYNC_WORKER_QUEUE (object);
	switch (property_id) {
		case FSO_FRAMEWORK_ASYNC_WORKER_QUEUE_T_TYPE:
		self->priv->t_type = g_value_get_gtype (value);
		break;
		case FSO_FRAMEWORK_ASYNC_WORKER_QUEUE_T_DUP_FUNC:
		self->priv->t_dup_func = g_value_get_pointer (value);
		break;
		case FSO_FRAMEWORK_ASYNC_WORKER_QUEUE_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;
	}
}



