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


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

typedef struct _fso_framework_asyncWaitSecondsData fso_framework_asyncWaitSecondsData;

#define FSO_FRAMEWORK_TYPE_SYNC_WRAPPER (fso_framework_sync_wrapper_get_type ())
#define FSO_FRAMEWORK_SYNC_WRAPPER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), FSO_FRAMEWORK_TYPE_SYNC_WRAPPER, FsoFrameworkSyncWrapper))
#define FSO_FRAMEWORK_SYNC_WRAPPER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), FSO_FRAMEWORK_TYPE_SYNC_WRAPPER, FsoFrameworkSyncWrapperClass))
#define FSO_FRAMEWORK_IS_SYNC_WRAPPER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), FSO_FRAMEWORK_TYPE_SYNC_WRAPPER))
#define FSO_FRAMEWORK_IS_SYNC_WRAPPER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), FSO_FRAMEWORK_TYPE_SYNC_WRAPPER))
#define FSO_FRAMEWORK_SYNC_WRAPPER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), FSO_FRAMEWORK_TYPE_SYNC_WRAPPER, FsoFrameworkSyncWrapperClass))

typedef struct _FsoFrameworkSyncWrapper FsoFrameworkSyncWrapper;
typedef struct _FsoFrameworkSyncWrapperClass FsoFrameworkSyncWrapperClass;
typedef struct _FsoFrameworkSyncWrapperPrivate FsoFrameworkSyncWrapperPrivate;
#define _g_main_loop_unref0(var) ((var == NULL) ? NULL : (var = (g_main_loop_unref (var), NULL)))

#define FSO_FRAMEWORK_TYPE_WAIT_FOR_PREDICATE (fso_framework_wait_for_predicate_get_type ())
#define FSO_FRAMEWORK_WAIT_FOR_PREDICATE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), FSO_FRAMEWORK_TYPE_WAIT_FOR_PREDICATE, FsoFrameworkWaitForPredicate))
#define FSO_FRAMEWORK_WAIT_FOR_PREDICATE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), FSO_FRAMEWORK_TYPE_WAIT_FOR_PREDICATE, FsoFrameworkWaitForPredicateClass))
#define FSO_FRAMEWORK_IS_WAIT_FOR_PREDICATE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), FSO_FRAMEWORK_TYPE_WAIT_FOR_PREDICATE))
#define FSO_FRAMEWORK_IS_WAIT_FOR_PREDICATE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), FSO_FRAMEWORK_TYPE_WAIT_FOR_PREDICATE))
#define FSO_FRAMEWORK_WAIT_FOR_PREDICATE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), FSO_FRAMEWORK_TYPE_WAIT_FOR_PREDICATE, FsoFrameworkWaitForPredicateClass))

typedef struct _FsoFrameworkWaitForPredicate FsoFrameworkWaitForPredicate;
typedef struct _FsoFrameworkWaitForPredicateClass FsoFrameworkWaitForPredicateClass;
typedef struct _FsoFrameworkWaitForPredicatePrivate FsoFrameworkWaitForPredicatePrivate;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

struct _fso_framework_asyncWaitSecondsData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GSimpleAsyncResult* _async_result;
	gint seconds;
	gint _tmp0_;
};

struct _FsoFrameworkSyncWrapper {
	GObject parent_instance;
	FsoFrameworkSyncWrapperPrivate * priv;
	GVoidFunc func;
	GMainLoop* loop;
};

struct _FsoFrameworkSyncWrapperClass {
	GObjectClass parent_class;
	gboolean (*onIdle) (FsoFrameworkSyncWrapper* self);
};

struct _FsoFrameworkWaitForPredicate {
	GObject parent_instance;
	FsoFrameworkWaitForPredicatePrivate * priv;
};

struct _FsoFrameworkWaitForPredicateClass {
	GObjectClass parent_class;
};

struct _FsoFrameworkWaitForPredicatePrivate {
	GSourceFunc func;
	gpointer func_target;
	GDestroyNotify func_target_destroy_notify;
	GMainLoop* loop;
	gint secs;
	gboolean timeout;
};


static gpointer fso_framework_sync_wrapper_parent_class = NULL;
static gpointer fso_framework_wait_for_predicate_parent_class = NULL;

static void fso_framework_asyncWaitSeconds_data_free (gpointer _data);
void fso_framework_asyncWaitSeconds (gint seconds, GAsyncReadyCallback _callback_, gpointer _user_data_);
void fso_framework_asyncWaitSeconds_finish (GAsyncResult* _res_);
static gboolean fso_framework_asyncWaitSeconds_co (fso_framework_asyncWaitSecondsData* _data_);
static gboolean _fso_framework_asyncWaitSeconds_co_gsource_func (gpointer self);
GType fso_framework_sync_wrapper_get_type (void) G_GNUC_CONST;
enum  {
	FSO_FRAMEWORK_SYNC_WRAPPER_DUMMY_PROPERTY
};
FsoFrameworkSyncWrapper* fso_framework_sync_wrapper_new (GVoidFunc func);
FsoFrameworkSyncWrapper* fso_framework_sync_wrapper_construct (GType object_type, GVoidFunc func);
gboolean fso_framework_sync_wrapper_onIdle (FsoFrameworkSyncWrapper* self);
static gboolean _fso_framework_sync_wrapper_onIdle_gsource_func (gpointer self);
static gboolean fso_framework_sync_wrapper_real_onIdle (FsoFrameworkSyncWrapper* self);
static void fso_framework_sync_wrapper_finalize (GObject* obj);
GType fso_framework_wait_for_predicate_get_type (void) G_GNUC_CONST;
#define FSO_FRAMEWORK_WAIT_FOR_PREDICATE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), FSO_FRAMEWORK_TYPE_WAIT_FOR_PREDICATE, FsoFrameworkWaitForPredicatePrivate))
enum  {
	FSO_FRAMEWORK_WAIT_FOR_PREDICATE_DUMMY_PROPERTY
};
gboolean fso_framework_wait_for_predicate_Wait (guint secs, GSourceFunc func, void* func_target, GDestroyNotify func_target_destroy_notify);
FsoFrameworkWaitForPredicate* fso_framework_wait_for_predicate_new (guint secs, GSourceFunc func, void* func_target, GDestroyNotify func_target_destroy_notify);
FsoFrameworkWaitForPredicate* fso_framework_wait_for_predicate_construct (GType object_type, guint secs, GSourceFunc func, void* func_target, GDestroyNotify func_target_destroy_notify);
gboolean fso_framework_wait_for_predicate_onTimeout (FsoFrameworkWaitForPredicate* self);
static gboolean _fso_framework_wait_for_predicate_onTimeout_gsource_func (gpointer self);
static void fso_framework_wait_for_predicate_finalize (GObject* obj);


static void fso_framework_asyncWaitSeconds_data_free (gpointer _data) {
	fso_framework_asyncWaitSecondsData* _data_;
	_data_ = _data;
	g_slice_free (fso_framework_asyncWaitSecondsData, _data_);
}


void fso_framework_asyncWaitSeconds (gint seconds, GAsyncReadyCallback _callback_, gpointer _user_data_) {
	fso_framework_asyncWaitSecondsData* _data_;
	gint _tmp0_;
	_data_ = g_slice_new0 (fso_framework_asyncWaitSecondsData);
	_data_->_async_result = g_simple_async_result_new (g_object_newv (G_TYPE_OBJECT, 0, NULL), _callback_, _user_data_, fso_framework_asyncWaitSeconds);
	g_simple_async_result_set_op_res_gpointer (_data_->_async_result, _data_, fso_framework_asyncWaitSeconds_data_free);
	_tmp0_ = seconds;
	_data_->seconds = _tmp0_;
	fso_framework_asyncWaitSeconds_co (_data_);
}


void fso_framework_asyncWaitSeconds_finish (GAsyncResult* _res_) {
	fso_framework_asyncWaitSecondsData* _data_;
	_data_ = g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (_res_));
}


static gboolean _fso_framework_asyncWaitSeconds_co_gsource_func (gpointer self) {
	gboolean result;
	result = fso_framework_asyncWaitSeconds_co (self);
	return result;
}


static gboolean fso_framework_asyncWaitSeconds_co (fso_framework_asyncWaitSecondsData* _data_) {
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = _data_->seconds;
	g_timeout_add_seconds_full (G_PRIORITY_DEFAULT, (guint) _data_->_tmp0_, _fso_framework_asyncWaitSeconds_co_gsource_func, _data_, NULL);
	_data_->_state_ = 1;
	return FALSE;
	_state_1:
	;
	if (_data_->_state_ == 0) {
		g_simple_async_result_complete_in_idle (_data_->_async_result);
	} else {
		g_simple_async_result_complete (_data_->_async_result);
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}


static gboolean _fso_framework_sync_wrapper_onIdle_gsource_func (gpointer self) {
	gboolean result;
	result = fso_framework_sync_wrapper_onIdle (self);
	return result;
}


FsoFrameworkSyncWrapper* fso_framework_sync_wrapper_construct (GType object_type, GVoidFunc func) {
	FsoFrameworkSyncWrapper * self = NULL;
	GVoidFunc _tmp0_;
	GMainLoop* _tmp1_;
	GMainLoop* _tmp2_;
	self = (FsoFrameworkSyncWrapper*) g_object_new (object_type, NULL);
	_tmp0_ = func;
	self->func = _tmp0_;
	_tmp1_ = g_main_loop_new (NULL, FALSE);
	_g_main_loop_unref0 (self->loop);
	self->loop = _tmp1_;
	g_idle_add_full (G_PRIORITY_DEFAULT_IDLE, _fso_framework_sync_wrapper_onIdle_gsource_func, g_object_ref (self), g_object_unref);
	_tmp2_ = self->loop;
	g_main_loop_run (_tmp2_);
	return self;
}


FsoFrameworkSyncWrapper* fso_framework_sync_wrapper_new (GVoidFunc func) {
	return fso_framework_sync_wrapper_construct (FSO_FRAMEWORK_TYPE_SYNC_WRAPPER, func);
}


static gboolean fso_framework_sync_wrapper_real_onIdle (FsoFrameworkSyncWrapper* self) {
	gboolean result = FALSE;
	GVoidFunc _tmp0_;
	GMainLoop* _tmp1_;
	_tmp0_ = self->func;
	_tmp0_ ();
	_tmp1_ = self->loop;
	g_main_loop_quit (_tmp1_);
	result = FALSE;
	return result;
}


gboolean fso_framework_sync_wrapper_onIdle (FsoFrameworkSyncWrapper* self) {
	g_return_val_if_fail (self != NULL, FALSE);
	return FSO_FRAMEWORK_SYNC_WRAPPER_GET_CLASS (self)->onIdle (self);
}


static void fso_framework_sync_wrapper_class_init (FsoFrameworkSyncWrapperClass * klass) {
	fso_framework_sync_wrapper_parent_class = g_type_class_peek_parent (klass);
	FSO_FRAMEWORK_SYNC_WRAPPER_CLASS (klass)->onIdle = fso_framework_sync_wrapper_real_onIdle;
	G_OBJECT_CLASS (klass)->finalize = fso_framework_sync_wrapper_finalize;
}


static void fso_framework_sync_wrapper_instance_init (FsoFrameworkSyncWrapper * self) {
}


static void fso_framework_sync_wrapper_finalize (GObject* obj) {
	FsoFrameworkSyncWrapper * self;
	self = FSO_FRAMEWORK_SYNC_WRAPPER (obj);
	_g_main_loop_unref0 (self->loop);
	G_OBJECT_CLASS (fso_framework_sync_wrapper_parent_class)->finalize (obj);
}


GType fso_framework_sync_wrapper_get_type (void) {
	static volatile gsize fso_framework_sync_wrapper_type_id__volatile = 0;
	if (g_once_init_enter (&fso_framework_sync_wrapper_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (FsoFrameworkSyncWrapperClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) fso_framework_sync_wrapper_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (FsoFrameworkSyncWrapper), 0, (GInstanceInitFunc) fso_framework_sync_wrapper_instance_init, NULL };
		GType fso_framework_sync_wrapper_type_id;
		fso_framework_sync_wrapper_type_id = g_type_register_static (G_TYPE_OBJECT, "FsoFrameworkSyncWrapper", &g_define_type_info, 0);
		g_once_init_leave (&fso_framework_sync_wrapper_type_id__volatile, fso_framework_sync_wrapper_type_id);
	}
	return fso_framework_sync_wrapper_type_id__volatile;
}


gboolean fso_framework_wait_for_predicate_Wait (guint secs, GSourceFunc func, void* func_target, GDestroyNotify func_target_destroy_notify) {
	gboolean result = FALSE;
	guint _tmp0_;
	GSourceFunc _tmp1_;
	void* _tmp1__target;
	FsoFrameworkWaitForPredicate* _tmp2_;
	FsoFrameworkWaitForPredicate* w;
	gboolean _tmp3_;
	_tmp0_ = secs;
	_tmp1_ = func;
	_tmp1__target = func_target;
	_tmp2_ = fso_framework_wait_for_predicate_new (_tmp0_, _tmp1_, _tmp1__target, NULL);
	w = _tmp2_;
	_tmp3_ = w->priv->timeout;
	result = _tmp3_;
	_g_object_unref0 (w);
	(func_target_destroy_notify == NULL) ? NULL : (func_target_destroy_notify (func_target), NULL);
	func = NULL;
	func_target = NULL;
	func_target_destroy_notify = NULL;
	return result;
}


static gboolean _fso_framework_wait_for_predicate_onTimeout_gsource_func (gpointer self) {
	gboolean result;
	result = fso_framework_wait_for_predicate_onTimeout (self);
	return result;
}


FsoFrameworkWaitForPredicate* fso_framework_wait_for_predicate_construct (GType object_type, guint secs, GSourceFunc func, void* func_target, GDestroyNotify func_target_destroy_notify) {
	FsoFrameworkWaitForPredicate * self = NULL;
	guint _tmp0_;
	GSourceFunc _tmp1_;
	void* _tmp1__target;
	GMainLoop* _tmp2_;
	GMainLoop* _tmp3_;
	self = (FsoFrameworkWaitForPredicate*) g_object_new (object_type, NULL);
	_tmp0_ = secs;
	self->priv->secs = (gint) _tmp0_;
	_tmp1_ = func;
	_tmp1__target = func_target;
	(self->priv->func_target_destroy_notify == NULL) ? NULL : (self->priv->func_target_destroy_notify (self->priv->func_target), NULL);
	self->priv->func = NULL;
	self->priv->func_target = NULL;
	self->priv->func_target_destroy_notify = NULL;
	self->priv->func = _tmp1_;
	self->priv->func_target = _tmp1__target;
	self->priv->func_target_destroy_notify = NULL;
	_tmp2_ = g_main_loop_new (NULL, FALSE);
	_g_main_loop_unref0 (self->priv->loop);
	self->priv->loop = _tmp2_;
	g_timeout_add_seconds_full (G_PRIORITY_DEFAULT, (guint) 1, _fso_framework_wait_for_predicate_onTimeout_gsource_func, g_object_ref (self), g_object_unref);
	_tmp3_ = self->priv->loop;
	g_main_loop_run (_tmp3_);
	(func_target_destroy_notify == NULL) ? NULL : (func_target_destroy_notify (func_target), NULL);
	func = NULL;
	func_target = NULL;
	func_target_destroy_notify = NULL;
	return self;
}


FsoFrameworkWaitForPredicate* fso_framework_wait_for_predicate_new (guint secs, GSourceFunc func, void* func_target, GDestroyNotify func_target_destroy_notify) {
	return fso_framework_wait_for_predicate_construct (FSO_FRAMEWORK_TYPE_WAIT_FOR_PREDICATE, secs, func, func_target, func_target_destroy_notify);
}


gboolean fso_framework_wait_for_predicate_onTimeout (FsoFrameworkWaitForPredicate* self) {
	gboolean result = FALSE;
	gint _tmp0_;
	GSourceFunc _tmp2_;
	void* _tmp2__target;
	gboolean _tmp3_ = FALSE;
	gboolean _tmp4_;
	g_return_val_if_fail (self != NULL, FALSE);
	_tmp0_ = self->priv->secs;
	self->priv->secs = _tmp0_ - 1;
	if (_tmp0_ == 0) {
		GMainLoop* _tmp1_;
		self->priv->timeout = TRUE;
		_tmp1_ = self->priv->loop;
		g_main_loop_quit (_tmp1_);
		result = FALSE;
		return result;
	}
	_tmp2_ = self->priv->func;
	_tmp2__target = self->priv->func_target;
	_tmp3_ = _tmp2_ (_tmp2__target);
	self->priv->timeout = _tmp3_;
	_tmp4_ = self->priv->timeout;
	if (!_tmp4_) {
		GMainLoop* _tmp5_;
		_tmp5_ = self->priv->loop;
		g_main_loop_quit (_tmp5_);
		result = FALSE;
		return result;
	}
	result = TRUE;
	return result;
}


static void fso_framework_wait_for_predicate_class_init (FsoFrameworkWaitForPredicateClass * klass) {
	fso_framework_wait_for_predicate_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (FsoFrameworkWaitForPredicatePrivate));
	G_OBJECT_CLASS (klass)->finalize = fso_framework_wait_for_predicate_finalize;
}


static void fso_framework_wait_for_predicate_instance_init (FsoFrameworkWaitForPredicate * self) {
	self->priv = FSO_FRAMEWORK_WAIT_FOR_PREDICATE_GET_PRIVATE (self);
}


static void fso_framework_wait_for_predicate_finalize (GObject* obj) {
	FsoFrameworkWaitForPredicate * self;
	self = FSO_FRAMEWORK_WAIT_FOR_PREDICATE (obj);
	(self->priv->func_target_destroy_notify == NULL) ? NULL : (self->priv->func_target_destroy_notify (self->priv->func_target), NULL);
	self->priv->func = NULL;
	self->priv->func_target = NULL;
	self->priv->func_target_destroy_notify = NULL;
	_g_main_loop_unref0 (self->priv->loop);
	G_OBJECT_CLASS (fso_framework_wait_for_predicate_parent_class)->finalize (obj);
}


GType fso_framework_wait_for_predicate_get_type (void) {
	static volatile gsize fso_framework_wait_for_predicate_type_id__volatile = 0;
	if (g_once_init_enter (&fso_framework_wait_for_predicate_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (FsoFrameworkWaitForPredicateClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) fso_framework_wait_for_predicate_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (FsoFrameworkWaitForPredicate), 0, (GInstanceInitFunc) fso_framework_wait_for_predicate_instance_init, NULL };
		GType fso_framework_wait_for_predicate_type_id;
		fso_framework_wait_for_predicate_type_id = g_type_register_static (G_TYPE_OBJECT, "FsoFrameworkWaitForPredicate", &g_define_type_info, 0);
		g_once_init_leave (&fso_framework_wait_for_predicate_type_id__volatile, fso_framework_wait_for_predicate_type_id);
	}
	return fso_framework_wait_for_predicate_type_id__volatile;
}



