/* async.c generated by valac 0.16.1, the Vala compiler
 * generated from async.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>
#include <sys/eventfd.h>
#include <unistd.h>
#include <sys/types.h>
#include <stdlib.h>
#include <string.h>
#include <gio/gio.h>

typedef struct _FsoFrameworkAsyncEventFd FsoFrameworkAsyncEventFd;
#define _g_io_channel_unref0(var) ((var == NULL) ? NULL : (var = (g_io_channel_unref (var), NULL)))

#define FSO_FRAMEWORK_ASYNC_TYPE_REACTOR_CHANNEL (fso_framework_async_reactor_channel_get_type ())
#define FSO_FRAMEWORK_ASYNC_REACTOR_CHANNEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), FSO_FRAMEWORK_ASYNC_TYPE_REACTOR_CHANNEL, FsoFrameworkAsyncReactorChannel))
#define FSO_FRAMEWORK_ASYNC_REACTOR_CHANNEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), FSO_FRAMEWORK_ASYNC_TYPE_REACTOR_CHANNEL, FsoFrameworkAsyncReactorChannelClass))
#define FSO_FRAMEWORK_ASYNC_IS_REACTOR_CHANNEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), FSO_FRAMEWORK_ASYNC_TYPE_REACTOR_CHANNEL))
#define FSO_FRAMEWORK_ASYNC_IS_REACTOR_CHANNEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), FSO_FRAMEWORK_ASYNC_TYPE_REACTOR_CHANNEL))
#define FSO_FRAMEWORK_ASYNC_REACTOR_CHANNEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), FSO_FRAMEWORK_ASYNC_TYPE_REACTOR_CHANNEL, FsoFrameworkAsyncReactorChannelClass))

typedef struct _FsoFrameworkAsyncReactorChannel FsoFrameworkAsyncReactorChannel;
typedef struct _FsoFrameworkAsyncReactorChannelClass FsoFrameworkAsyncReactorChannelClass;
typedef struct _FsoFrameworkAsyncReactorChannelPrivate FsoFrameworkAsyncReactorChannelPrivate;

#define FSO_FRAMEWORK_TYPE_LOGGER (fso_framework_logger_get_type ())
#define FSO_FRAMEWORK_LOGGER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), FSO_FRAMEWORK_TYPE_LOGGER, FsoFrameworkLogger))
#define FSO_FRAMEWORK_IS_LOGGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), FSO_FRAMEWORK_TYPE_LOGGER))
#define FSO_FRAMEWORK_LOGGER_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), FSO_FRAMEWORK_TYPE_LOGGER, FsoFrameworkLoggerIface))

typedef struct _FsoFrameworkLogger FsoFrameworkLogger;
typedef struct _FsoFrameworkLoggerIface FsoFrameworkLoggerIface;
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef struct _Block4Data Block4Data;
typedef struct _FsoFrameworkAsyncSleepAsyncData FsoFrameworkAsyncSleepAsyncData;

struct _FsoFrameworkAsyncEventFd {
	GIOChannel* channel;
	guint watch;
};

struct _FsoFrameworkAsyncReactorChannel {
	GObject parent_instance;
	FsoFrameworkAsyncReactorChannelPrivate * priv;
};

struct _FsoFrameworkAsyncReactorChannelClass {
	GObjectClass parent_class;
};

typedef void (*FsoFrameworkAsyncReactorChannelActionFunc) (void* data, gssize length, void* user_data);
struct _FsoFrameworkAsyncReactorChannelPrivate {
	gint fd;
	guint watch;
	GIOChannel* channel;
	FsoFrameworkAsyncReactorChannelActionFunc actionfunc;
	gpointer actionfunc_target;
	GDestroyNotify actionfunc_target_destroy_notify;
	gchar* buffer;
	gint buffer_length1;
	gint _buffer_size_;
	gboolean rewind_flag;
};

typedef gchar* (*ReprDelegate) (void* user_data);
struct _FsoFrameworkLoggerIface {
	GTypeInterface parent_iface;
	void (*setLevel) (FsoFrameworkLogger* self, GLogLevelFlags level);
	void (*setDestination) (FsoFrameworkLogger* self, const gchar* destination);
	void (*setReprDelegate) (FsoFrameworkLogger* self, ReprDelegate repr, void* repr_target);
	GLogLevelFlags (*getLevel) (FsoFrameworkLogger* self);
	gchar* (*getDestination) (FsoFrameworkLogger* self);
	gboolean (*debug) (FsoFrameworkLogger* self, const gchar* message);
	gboolean (*info) (FsoFrameworkLogger* self, const gchar* message);
	gboolean (*warning) (FsoFrameworkLogger* self, const gchar* message);
	gboolean (*error) (FsoFrameworkLogger* self, const gchar* message);
	gboolean (*critical) (FsoFrameworkLogger* self, const gchar* message);
	gboolean (*data) (FsoFrameworkLogger* self, guint8* message, int message_length1, gboolean in, GLogLevelFlags when);
};

struct _Block4Data {
	int _ref_count_;
	gboolean interrupted;
	gpointer _async_data_;
};

struct _FsoFrameworkAsyncSleepAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GSimpleAsyncResult* _async_result;
	gint timeout;
	GCancellable* cancellable;
	Block4Data* _data4_;
	gulong cancel;
	guint timeout_src;
	GCancellable* _tmp0_;
	GCancellable* _tmp1_;
	gboolean _tmp2_;
	GCancellable* _tmp3_;
	gulong _tmp4_;
	gint _tmp5_;
	guint _tmp6_;
	guint _tmp7_;
	gboolean _tmp8_;
	gulong _tmp9_;
	gboolean _tmp10_;
	gboolean _tmp11_;
	GCancellable* _tmp12_;
	gulong _tmp13_;
};


static gpointer fso_framework_async_reactor_channel_parent_class = NULL;
extern FsoFrameworkLogger* fso_framework_theLogger;

void fso_framework_async_event_fd_free (FsoFrameworkAsyncEventFd* self);
static void fso_framework_async_event_fd_instance_init (FsoFrameworkAsyncEventFd * self);
FsoFrameworkAsyncEventFd* fso_framework_async_event_fd_new (guint initvalue, GIOFunc callback, void* callback_target);
FsoFrameworkAsyncEventFd* fso_framework_async_event_fd_new (guint initvalue, GIOFunc callback, void* callback_target);
void fso_framework_async_event_fd_write (FsoFrameworkAsyncEventFd* self, gint count);
guint fso_framework_async_event_fd_read (FsoFrameworkAsyncEventFd* self);
GType fso_framework_async_reactor_channel_get_type (void) G_GNUC_CONST;
#define FSO_FRAMEWORK_ASYNC_REACTOR_CHANNEL_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), FSO_FRAMEWORK_ASYNC_TYPE_REACTOR_CHANNEL, FsoFrameworkAsyncReactorChannelPrivate))
enum  {
	FSO_FRAMEWORK_ASYNC_REACTOR_CHANNEL_DUMMY_PROPERTY
};
static void fso_framework_async_reactor_channel_init (FsoFrameworkAsyncReactorChannel* self, gint fd, FsoFrameworkAsyncReactorChannelActionFunc actionfunc, void* actionfunc_target, GDestroyNotify actionfunc_target_destroy_notify, gsize bufferlength);
FsoFrameworkAsyncReactorChannel* fso_framework_async_reactor_channel_new (gint fd, FsoFrameworkAsyncReactorChannelActionFunc actionfunc, void* actionfunc_target, GDestroyNotify actionfunc_target_destroy_notify, gsize bufferlength);
FsoFrameworkAsyncReactorChannel* fso_framework_async_reactor_channel_construct (GType object_type, gint fd, FsoFrameworkAsyncReactorChannelActionFunc actionfunc, void* actionfunc_target, GDestroyNotify actionfunc_target_destroy_notify, gsize bufferlength);
static gboolean fso_framework_async_reactor_channel_onActionFromChannel (FsoFrameworkAsyncReactorChannel* self, GIOChannel* source, GIOCondition condition);
static gboolean _fso_framework_async_reactor_channel_onActionFromChannel_gio_func (GIOChannel* source, GIOCondition condition, gpointer self);
FsoFrameworkAsyncReactorChannel* fso_framework_async_reactor_channel_new_rewind (gint fd, FsoFrameworkAsyncReactorChannelActionFunc actionfunc, void* actionfunc_target, GDestroyNotify actionfunc_target_destroy_notify, gsize bufferlength);
FsoFrameworkAsyncReactorChannel* fso_framework_async_reactor_channel_construct_rewind (GType object_type, gint fd, FsoFrameworkAsyncReactorChannelActionFunc actionfunc, void* actionfunc_target, GDestroyNotify actionfunc_target_destroy_notify, gsize bufferlength);
gint fso_framework_async_reactor_channel_fileno (FsoFrameworkAsyncReactorChannel* self);
GType fso_framework_logger_get_type (void) G_GNUC_CONST;
gboolean fso_framework_logger_error (FsoFrameworkLogger* self, const gchar* message);
static void fso_framework_async_reactor_channel_finalize (GObject* obj);
static void fso_framework_async_sleep_async_data_free (gpointer _data);
void fso_framework_async_sleep_async (gint timeout, GCancellable* cancellable, GAsyncReadyCallback _callback_, gpointer _user_data_);
void fso_framework_async_sleep_finish (GAsyncResult* _res_);
static gboolean fso_framework_async_sleep_async_co (FsoFrameworkAsyncSleepAsyncData* _data_);
static Block4Data* block4_data_ref (Block4Data* _data4_);
static void block4_data_unref (void * _userdata_);
static void ___lambda4_ (Block4Data* _data4_);
static void ____lambda4__g_cancellable_cancelled (GCancellable* _sender, gpointer self);
static gboolean _fso_framework_async_sleep_async_co_gsource_func (gpointer self);


FsoFrameworkAsyncEventFd* fso_framework_async_event_fd_new (guint initvalue, GIOFunc callback, void* callback_target) {
	FsoFrameworkAsyncEventFd* self;
	guint _tmp0_;
	gint _tmp1_ = 0;
	GIOChannel* _tmp2_;
	GIOChannel* _tmp3_;
	GIOFunc _tmp4_;
	void* _tmp4__target;
	guint _tmp5_ = 0U;
	self = g_slice_new0 (FsoFrameworkAsyncEventFd);
	fso_framework_async_event_fd_instance_init (self);
	_tmp0_ = initvalue;
	_tmp1_ = eventfd (_tmp0_, 0);
	_tmp2_ = g_io_channel_unix_new (_tmp1_);
	_g_io_channel_unref0 (self->channel);
	self->channel = _tmp2_;
	_tmp3_ = self->channel;
	_tmp4_ = callback;
	_tmp4__target = callback_target;
	_tmp5_ = g_io_add_watch (_tmp3_, G_IO_IN, _tmp4_, _tmp4__target);
	self->watch = _tmp5_;
	return self;
}


void fso_framework_async_event_fd_write (FsoFrameworkAsyncEventFd* self, gint count) {
	GIOChannel* _tmp0_;
	gint _tmp1_ = 0;
	gint _tmp2_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->channel;
	_tmp1_ = g_io_channel_unix_get_fd (_tmp0_);
	_tmp2_ = count;
	eventfd_write (_tmp1_, (guint64) _tmp2_);
}


guint fso_framework_async_event_fd_read (FsoFrameworkAsyncEventFd* self) {
	guint result = 0U;
	guint64 _result_ = 0ULL;
	GIOChannel* _tmp0_;
	gint _tmp1_ = 0;
	guint64 _tmp2_ = 0ULL;
	g_return_val_if_fail (self != NULL, 0U);
	_tmp0_ = self->channel;
	_tmp1_ = g_io_channel_unix_get_fd (_tmp0_);
	eventfd_read (_tmp1_, &_tmp2_);
	_result_ = _tmp2_;
	result = (guint) _result_;
	return result;
}


static void fso_framework_async_event_fd_instance_init (FsoFrameworkAsyncEventFd * self) {
}


void fso_framework_async_event_fd_free (FsoFrameworkAsyncEventFd* self) {
	guint _tmp0_;
	_tmp0_ = self->watch;
	g_source_remove (_tmp0_);
	_g_io_channel_unref0 (self->channel);
	self->channel = NULL;
	_g_io_channel_unref0 (self->channel);
	g_slice_free (FsoFrameworkAsyncEventFd, self);
}


static void fso_framework_async_reactor_channel_init (FsoFrameworkAsyncReactorChannel* self, gint fd, FsoFrameworkAsyncReactorChannelActionFunc actionfunc, void* actionfunc_target, GDestroyNotify actionfunc_target_destroy_notify, gsize bufferlength) {
	gint _tmp0_;
	gint _tmp1_;
	GIOChannel* _tmp2_;
	GIOChannel* _tmp3_;
	gint _tmp4_;
	FsoFrameworkAsyncReactorChannelActionFunc _tmp5_;
	void* _tmp5__target;
	gsize _tmp6_;
	gchar* _tmp7_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = fd;
	g_assert (_tmp0_ > (-1));
	_tmp1_ = fd;
	_tmp2_ = g_io_channel_unix_new (_tmp1_);
	_g_io_channel_unref0 (self->priv->channel);
	self->priv->channel = _tmp2_;
	_tmp3_ = self->priv->channel;
	g_assert (_tmp3_ != NULL);
	_tmp4_ = fd;
	self->priv->fd = _tmp4_;
	_tmp5_ = actionfunc;
	_tmp5__target = actionfunc_target;
	(self->priv->actionfunc_target_destroy_notify == NULL) ? NULL : (self->priv->actionfunc_target_destroy_notify (self->priv->actionfunc_target), NULL);
	self->priv->actionfunc = NULL;
	self->priv->actionfunc_target = NULL;
	self->priv->actionfunc_target_destroy_notify = NULL;
	self->priv->actionfunc = _tmp5_;
	self->priv->actionfunc_target = _tmp5__target;
	self->priv->actionfunc_target_destroy_notify = NULL;
	_tmp6_ = bufferlength;
	_tmp7_ = g_new0 (gchar, _tmp6_);
	self->priv->buffer = (g_free (self->priv->buffer), NULL);
	self->priv->buffer = _tmp7_;
	self->priv->buffer_length1 = _tmp6_;
	self->priv->_buffer_size_ = self->priv->buffer_length1;
	(actionfunc_target_destroy_notify == NULL) ? NULL : (actionfunc_target_destroy_notify (actionfunc_target), NULL);
	actionfunc = NULL;
	actionfunc_target = NULL;
	actionfunc_target_destroy_notify = NULL;
}


static gboolean _fso_framework_async_reactor_channel_onActionFromChannel_gio_func (GIOChannel* source, GIOCondition condition, gpointer self) {
	gboolean result;
	result = fso_framework_async_reactor_channel_onActionFromChannel (self, source, condition);
	return result;
}


FsoFrameworkAsyncReactorChannel* fso_framework_async_reactor_channel_construct (GType object_type, gint fd, FsoFrameworkAsyncReactorChannelActionFunc actionfunc, void* actionfunc_target, GDestroyNotify actionfunc_target_destroy_notify, gsize bufferlength) {
	FsoFrameworkAsyncReactorChannel * self = NULL;
	gint _tmp0_;
	FsoFrameworkAsyncReactorChannelActionFunc _tmp1_;
	void* _tmp1__target;
	gsize _tmp2_;
	GIOChannel* _tmp3_;
	guint _tmp4_ = 0U;
	self = (FsoFrameworkAsyncReactorChannel*) g_object_new (object_type, NULL);
	_tmp0_ = fd;
	_tmp1_ = actionfunc;
	_tmp1__target = actionfunc_target;
	_tmp2_ = bufferlength;
	fso_framework_async_reactor_channel_init (self, _tmp0_, _tmp1_, _tmp1__target, NULL, _tmp2_);
	_tmp3_ = self->priv->channel;
	_tmp4_ = g_io_add_watch (_tmp3_, G_IO_IN | G_IO_HUP, _fso_framework_async_reactor_channel_onActionFromChannel_gio_func, self);
	self->priv->watch = _tmp4_;
	self->priv->rewind_flag = FALSE;
	(actionfunc_target_destroy_notify == NULL) ? NULL : (actionfunc_target_destroy_notify (actionfunc_target), NULL);
	actionfunc = NULL;
	actionfunc_target = NULL;
	actionfunc_target_destroy_notify = NULL;
	return self;
}


FsoFrameworkAsyncReactorChannel* fso_framework_async_reactor_channel_new (gint fd, FsoFrameworkAsyncReactorChannelActionFunc actionfunc, void* actionfunc_target, GDestroyNotify actionfunc_target_destroy_notify, gsize bufferlength) {
	return fso_framework_async_reactor_channel_construct (FSO_FRAMEWORK_ASYNC_TYPE_REACTOR_CHANNEL, fd, actionfunc, actionfunc_target, actionfunc_target_destroy_notify, bufferlength);
}


FsoFrameworkAsyncReactorChannel* fso_framework_async_reactor_channel_construct_rewind (GType object_type, gint fd, FsoFrameworkAsyncReactorChannelActionFunc actionfunc, void* actionfunc_target, GDestroyNotify actionfunc_target_destroy_notify, gsize bufferlength) {
	FsoFrameworkAsyncReactorChannel * self = NULL;
	gint _tmp0_;
	FsoFrameworkAsyncReactorChannelActionFunc _tmp1_;
	void* _tmp1__target;
	gsize _tmp2_;
	GIOChannel* _tmp3_;
	guint _tmp4_ = 0U;
	self = (FsoFrameworkAsyncReactorChannel*) g_object_new (object_type, NULL);
	_tmp0_ = fd;
	_tmp1_ = actionfunc;
	_tmp1__target = actionfunc_target;
	_tmp2_ = bufferlength;
	fso_framework_async_reactor_channel_init (self, _tmp0_, _tmp1_, _tmp1__target, NULL, _tmp2_);
	_tmp3_ = self->priv->channel;
	_tmp4_ = g_io_add_watch (_tmp3_, (G_IO_IN | G_IO_PRI) | G_IO_HUP, _fso_framework_async_reactor_channel_onActionFromChannel_gio_func, self);
	self->priv->watch = _tmp4_;
	self->priv->rewind_flag = TRUE;
	(actionfunc_target_destroy_notify == NULL) ? NULL : (actionfunc_target_destroy_notify (actionfunc_target), NULL);
	actionfunc = NULL;
	actionfunc_target = NULL;
	actionfunc_target_destroy_notify = NULL;
	return self;
}


FsoFrameworkAsyncReactorChannel* fso_framework_async_reactor_channel_new_rewind (gint fd, FsoFrameworkAsyncReactorChannelActionFunc actionfunc, void* actionfunc_target, GDestroyNotify actionfunc_target_destroy_notify, gsize bufferlength) {
	return fso_framework_async_reactor_channel_construct_rewind (FSO_FRAMEWORK_ASYNC_TYPE_REACTOR_CHANNEL, fd, actionfunc, actionfunc_target, actionfunc_target_destroy_notify, bufferlength);
}


gint fso_framework_async_reactor_channel_fileno (FsoFrameworkAsyncReactorChannel* self) {
	gint result = 0;
	gint _tmp0_;
	g_return_val_if_fail (self != NULL, 0);
	_tmp0_ = self->priv->fd;
	result = _tmp0_;
	return result;
}


static gboolean fso_framework_async_reactor_channel_onActionFromChannel (FsoFrameworkAsyncReactorChannel* self, GIOChannel* source, GIOCondition condition) {
	gboolean result = FALSE;
	GIOCondition _tmp0_;
	gboolean _tmp2_ = FALSE;
	GIOCondition _tmp3_;
	gboolean _tmp5_;
	FsoFrameworkLogger* _tmp17_;
	GIOCondition _tmp18_;
	gchar* _tmp19_ = NULL;
	gchar* _tmp20_;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (source != NULL, FALSE);
	_tmp0_ = condition;
	if ((_tmp0_ & G_IO_HUP) == G_IO_HUP) {
		FsoFrameworkAsyncReactorChannelActionFunc _tmp1_;
		void* _tmp1__target;
		_tmp1_ = self->priv->actionfunc;
		_tmp1__target = self->priv->actionfunc_target;
		_tmp1_ (NULL, (gssize) 0, _tmp1__target);
		result = FALSE;
		return result;
	}
	_tmp3_ = condition;
	if ((_tmp3_ & G_IO_IN) == G_IO_IN) {
		_tmp2_ = TRUE;
	} else {
		GIOCondition _tmp4_;
		_tmp4_ = condition;
		_tmp2_ = (_tmp4_ & G_IO_PRI) == G_IO_PRI;
	}
	_tmp5_ = _tmp2_;
	if (_tmp5_) {
		gint _tmp6_;
		gchar* _tmp7_;
		gint _tmp7__length1;
		gboolean _tmp8_;
		gint _tmp10_;
		gchar* _tmp11_;
		gint _tmp11__length1;
		gchar* _tmp12_;
		gint _tmp12__length1;
		gssize _tmp13_ = 0L;
		gssize bytesread;
		FsoFrameworkAsyncReactorChannelActionFunc _tmp14_;
		void* _tmp14__target;
		gchar* _tmp15_;
		gint _tmp15__length1;
		gssize _tmp16_;
		_tmp6_ = self->priv->fd;
		g_assert (_tmp6_ != (-1));
		_tmp7_ = self->priv->buffer;
		_tmp7__length1 = self->priv->buffer_length1;
		g_assert (_tmp7_ != NULL);
		_tmp8_ = self->priv->rewind_flag;
		if (_tmp8_) {
			gint _tmp9_;
			_tmp9_ = self->priv->fd;
			lseek (_tmp9_, (off_t) 0, SEEK_SET);
		}
		_tmp10_ = self->priv->fd;
		_tmp11_ = self->priv->buffer;
		_tmp11__length1 = self->priv->buffer_length1;
		_tmp12_ = self->priv->buffer;
		_tmp12__length1 = self->priv->buffer_length1;
		_tmp13_ = read (_tmp10_, _tmp11_, (gsize) _tmp12__length1);
		bytesread = _tmp13_;
		_tmp14_ = self->priv->actionfunc;
		_tmp14__target = self->priv->actionfunc_target;
		_tmp15_ = self->priv->buffer;
		_tmp15__length1 = self->priv->buffer_length1;
		_tmp16_ = bytesread;
		_tmp14_ (_tmp15_, _tmp16_, _tmp14__target);
		result = TRUE;
		return result;
	}
	_tmp17_ = fso_framework_theLogger;
	_tmp18_ = condition;
	_tmp19_ = g_strdup_printf ("Unsupported IOCondition %u", (guint) ((gint) _tmp18_));
	_tmp20_ = _tmp19_;
	fso_framework_logger_error (_tmp17_, _tmp20_);
	_g_free0 (_tmp20_);
	result = TRUE;
	return result;
}


static void fso_framework_async_reactor_channel_class_init (FsoFrameworkAsyncReactorChannelClass * klass) {
	fso_framework_async_reactor_channel_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (FsoFrameworkAsyncReactorChannelPrivate));
	G_OBJECT_CLASS (klass)->finalize = fso_framework_async_reactor_channel_finalize;
}


static void fso_framework_async_reactor_channel_instance_init (FsoFrameworkAsyncReactorChannel * self) {
	self->priv = FSO_FRAMEWORK_ASYNC_REACTOR_CHANNEL_GET_PRIVATE (self);
}


static void fso_framework_async_reactor_channel_finalize (GObject* obj) {
	FsoFrameworkAsyncReactorChannel * self;
	guint _tmp0_;
	gint _tmp1_;
	self = FSO_FRAMEWORK_ASYNC_REACTOR_CHANNEL (obj);
	_g_io_channel_unref0 (self->priv->channel);
	self->priv->channel = NULL;
	_tmp0_ = self->priv->watch;
	g_source_remove (_tmp0_);
	_tmp1_ = self->priv->fd;
	close (_tmp1_);
	_g_io_channel_unref0 (self->priv->channel);
	(self->priv->actionfunc_target_destroy_notify == NULL) ? NULL : (self->priv->actionfunc_target_destroy_notify (self->priv->actionfunc_target), NULL);
	self->priv->actionfunc = NULL;
	self->priv->actionfunc_target = NULL;
	self->priv->actionfunc_target_destroy_notify = NULL;
	self->priv->buffer = (g_free (self->priv->buffer), NULL);
	G_OBJECT_CLASS (fso_framework_async_reactor_channel_parent_class)->finalize (obj);
}


/**
     * @class ReactorChannel
     **/
GType fso_framework_async_reactor_channel_get_type (void) {
	static volatile gsize fso_framework_async_reactor_channel_type_id__volatile = 0;
	if (g_once_init_enter (&fso_framework_async_reactor_channel_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (FsoFrameworkAsyncReactorChannelClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) fso_framework_async_reactor_channel_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (FsoFrameworkAsyncReactorChannel), 0, (GInstanceInitFunc) fso_framework_async_reactor_channel_instance_init, NULL };
		GType fso_framework_async_reactor_channel_type_id;
		fso_framework_async_reactor_channel_type_id = g_type_register_static (G_TYPE_OBJECT, "FsoFrameworkAsyncReactorChannel", &g_define_type_info, 0);
		g_once_init_leave (&fso_framework_async_reactor_channel_type_id__volatile, fso_framework_async_reactor_channel_type_id);
	}
	return fso_framework_async_reactor_channel_type_id__volatile;
}


static void fso_framework_async_sleep_async_data_free (gpointer _data) {
	FsoFrameworkAsyncSleepAsyncData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->cancellable);
	g_slice_free (FsoFrameworkAsyncSleepAsyncData, _data_);
}


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


void fso_framework_async_sleep_async (gint timeout, GCancellable* cancellable, GAsyncReadyCallback _callback_, gpointer _user_data_) {
	FsoFrameworkAsyncSleepAsyncData* _data_;
	gint _tmp0_;
	GCancellable* _tmp1_;
	GCancellable* _tmp2_;
	_data_ = g_slice_new0 (FsoFrameworkAsyncSleepAsyncData);
	_data_->_async_result = g_simple_async_result_new (g_object_newv (G_TYPE_OBJECT, 0, NULL), _callback_, _user_data_, fso_framework_async_sleep_async);
	g_simple_async_result_set_op_res_gpointer (_data_->_async_result, _data_, fso_framework_async_sleep_async_data_free);
	_tmp0_ = timeout;
	_data_->timeout = _tmp0_;
	_tmp1_ = cancellable;
	_tmp2_ = _g_object_ref0 (_tmp1_);
	_data_->cancellable = _tmp2_;
	fso_framework_async_sleep_async_co (_data_);
}


void fso_framework_async_sleep_finish (GAsyncResult* _res_) {
	FsoFrameworkAsyncSleepAsyncData* _data_;
	_data_ = g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (_res_));
}


static Block4Data* block4_data_ref (Block4Data* _data4_) {
	g_atomic_int_inc (&_data4_->_ref_count_);
	return _data4_;
}


static void block4_data_unref (void * _userdata_) {
	Block4Data* _data4_;
	_data4_ = (Block4Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data4_->_ref_count_)) {
		g_slice_free (Block4Data, _data4_);
	}
}


static void ___lambda4_ (Block4Data* _data4_) {
	_data4_->interrupted = TRUE;
	fso_framework_async_sleep_async_co (_data4_->_async_data_);
}


static void ____lambda4__g_cancellable_cancelled (GCancellable* _sender, gpointer self) {
	___lambda4_ (self);
}


static gboolean _fso_framework_async_sleep_async_co_gsource_func (gpointer self) {
	gboolean result;
	result = fso_framework_async_sleep_async_co (self);
	return result;
}


static gboolean fso_framework_async_sleep_async_co (FsoFrameworkAsyncSleepAsyncData* _data_) {
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_data4_ = g_slice_new0 (Block4Data);
	_data_->_data4_->_ref_count_ = 1;
	_data_->_data4_->_async_data_ = _data_;
	_data_->cancel = (gulong) 0;
	_data_->timeout_src = (guint) 0;
	_data_->_data4_->interrupted = FALSE;
	_data_->_tmp0_ = _data_->cancellable;
	if (_data_->_tmp0_ != NULL) {
		_data_->_tmp1_ = _data_->cancellable;
		_data_->_tmp2_ = FALSE;
		_data_->_tmp2_ = g_cancellable_is_cancelled (_data_->_tmp1_);
		if (_data_->_tmp2_) {
			block4_data_unref (_data_->_data4_);
			_data_->_data4_ = NULL;
			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;
		}
		_data_->_tmp3_ = _data_->cancellable;
		_data_->_tmp4_ = 0UL;
		_data_->_tmp4_ = g_signal_connect_data (_data_->_tmp3_, "cancelled", (GCallback) ____lambda4__g_cancellable_cancelled, block4_data_ref (_data_->_data4_), (GClosureNotify) block4_data_unref, 0);
		_data_->cancel = _data_->_tmp4_;
	}
	_data_->_tmp5_ = _data_->timeout;
	_data_->_tmp6_ = 0U;
	_data_->_tmp6_ = g_timeout_add_full (G_PRIORITY_DEFAULT, (guint) _data_->_tmp5_, _fso_framework_async_sleep_async_co_gsource_func, _data_, NULL);
	_data_->timeout_src = _data_->_tmp6_;
	_data_->_state_ = 1;
	return FALSE;
	_state_1:
	;
	_data_->_tmp7_ = _data_->timeout_src;
	g_source_remove (_data_->_tmp7_);
	_data_->_tmp9_ = _data_->cancel;
	if (_data_->_tmp9_ != ((gulong) 0)) {
		_data_->_tmp10_ = _data_->_data4_->interrupted;
		_data_->_tmp8_ = !_data_->_tmp10_;
	} else {
		_data_->_tmp8_ = FALSE;
	}
	_data_->_tmp11_ = _data_->_tmp8_;
	if (_data_->_tmp11_) {
		_data_->_tmp12_ = _data_->cancellable;
		_data_->_tmp13_ = _data_->cancel;
		g_cancellable_disconnect (_data_->_tmp12_, _data_->_tmp13_);
	}
	block4_data_unref (_data_->_data4_);
	_data_->_data4_ = NULL;
	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;
}



