/* async-closure.c generated by valac 0.30.1, the Vala compiler
 * generated from async-closure.vala, do not modify */


#include <glib.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <gio/gio.h>
#include <stdio.h>


#define TYPE_TEST (test_get_type ())
#define TEST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TEST, Test))
#define TEST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_TEST, TestClass))
#define IS_TEST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_TEST))
#define IS_TEST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_TEST))
#define TEST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_TEST, TestClass))

typedef struct _Test Test;
typedef struct _TestClass TestClass;
typedef struct _TestPrivate TestPrivate;
#define _g_free0(var) (var = (g_free (var), NULL))
typedef struct _Block1Data Block1Data;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef struct _Block2Data Block2Data;
typedef struct _TestTestAsyncData TestTestAsyncData;
typedef struct _Block3Data Block3Data;
#define _g_main_loop_unref0(var) ((var == NULL) ? NULL : (var = (g_main_loop_unref (var), NULL)))

struct _Test {
	GObject parent_instance;
	TestPrivate * priv;
};

struct _TestClass {
	GObjectClass parent_class;
};

struct _Block1Data {
	int _ref_count_;
	Test* self;
	gchar* data;
};

struct _Block2Data {
	int _ref_count_;
	Test* self;
	gchar* data;
	gpointer _async_data_;
};

struct _TestTestAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GSimpleAsyncResult* _async_result;
	Test* self;
	gchar* data;
	Block2Data* _data2_;
	const gchar* _tmp0_;
};

struct _Block3Data {
	int _ref_count_;
	Test* instance;
};


static gpointer test_parent_class = NULL;

GType test_get_type (void) G_GNUC_CONST;
enum  {
	TEST_DUMMY_PROPERTY
};
void test_test_sync (Test* self, const gchar* data);
static Block1Data* block1_data_ref (Block1Data* _data1_);
static void block1_data_unref (void * _userdata_);
static gboolean __lambda4_ (Block1Data* _data1_);
static void test_do_something (Test* self, const gchar* data);
static gboolean ___lambda4__gsource_func (gpointer self);
static void test_test_async_data_free (gpointer _data);
void test_test_async (Test* self, const gchar* data, GAsyncReadyCallback _callback_, gpointer _user_data_);
void test_test_finish (Test* self, GAsyncResult* _res_);
static gboolean test_test_async_co (TestTestAsyncData* _data_);
static Block2Data* block2_data_ref (Block2Data* _data2_);
static void block2_data_unref (void * _userdata_);
static gboolean __lambda5_ (Block2Data* _data2_);
static gboolean ___lambda5__gsource_func (gpointer self);
static gboolean _test_test_async_co_gsource_func (gpointer self);
Test* test_new (void);
Test* test_construct (GType object_type);
gint _vala_main (gchar** argv, int argv_length1);
static Block3Data* block3_data_ref (Block3Data* _data3_);
static void block3_data_unref (void * _userdata_);
static void __lambda6_ (Block3Data* _data3_, GObject* obj, GAsyncResult* res);
static void ___lambda6__gasync_ready_callback (GObject* source_object, GAsyncResult* res, gpointer self);


static Block1Data* block1_data_ref (Block1Data* _data1_) {
	g_atomic_int_inc (&_data1_->_ref_count_);
	return _data1_;
}


static void block1_data_unref (void * _userdata_) {
	Block1Data* _data1_;
	_data1_ = (Block1Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data1_->_ref_count_)) {
		Test* self;
		self = _data1_->self;
		_g_free0 (_data1_->data);
		_g_object_unref0 (self);
		g_slice_free (Block1Data, _data1_);
	}
}


static gboolean __lambda4_ (Block1Data* _data1_) {
	Test* self;
	gboolean result = FALSE;
	const gchar* _tmp0_ = NULL;
	self = _data1_->self;
	_tmp0_ = _data1_->data;
	test_do_something (self, _tmp0_);
	result = FALSE;
	return result;
}


static gboolean ___lambda4__gsource_func (gpointer self) {
	gboolean result;
	result = __lambda4_ (self);
	return result;
}


void test_test_sync (Test* self, const gchar* data) {
	Block1Data* _data1_;
	const gchar* _tmp0_ = NULL;
	gchar* _tmp1_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (data != NULL);
	_data1_ = g_slice_new0 (Block1Data);
	_data1_->_ref_count_ = 1;
	_data1_->self = g_object_ref (self);
	_tmp0_ = data;
	_tmp1_ = g_strdup (_tmp0_);
	_g_free0 (_data1_->data);
	_data1_->data = _tmp1_;
	g_idle_add_full (G_PRIORITY_DEFAULT_IDLE, ___lambda4__gsource_func, block1_data_ref (_data1_), block1_data_unref);
	block1_data_unref (_data1_);
	_data1_ = NULL;
}


static void test_test_async_data_free (gpointer _data) {
	TestTestAsyncData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->self);
	g_slice_free (TestTestAsyncData, _data_);
}


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


void test_test_async (Test* self, const gchar* data, GAsyncReadyCallback _callback_, gpointer _user_data_) {
	TestTestAsyncData* _data_;
	Test* _tmp0_ = NULL;
	const gchar* _tmp1_ = NULL;
	gchar* _tmp2_ = NULL;
	_data_ = g_slice_new0 (TestTestAsyncData);
	_data_->_async_result = g_simple_async_result_new (G_OBJECT (self), _callback_, _user_data_, test_test_async);
	g_simple_async_result_set_op_res_gpointer (_data_->_async_result, _data_, test_test_async_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = data;
	_tmp2_ = g_strdup (_tmp1_);
	_g_free0 (_data_->data);
	_data_->data = _tmp2_;
	test_test_async_co (_data_);
}


void test_test_finish (Test* self, GAsyncResult* _res_) {
	TestTestAsyncData* _data_;
	_data_ = g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (_res_));
}


static Block2Data* block2_data_ref (Block2Data* _data2_) {
	g_atomic_int_inc (&_data2_->_ref_count_);
	return _data2_;
}


static void block2_data_unref (void * _userdata_) {
	Block2Data* _data2_;
	_data2_ = (Block2Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data2_->_ref_count_)) {
		Test* self;
		self = _data2_->self;
		_g_free0 (_data2_->data);
		_g_object_unref0 (self);
		g_slice_free (Block2Data, _data2_);
	}
}


static gboolean __lambda5_ (Block2Data* _data2_) {
	Test* self;
	gboolean result = FALSE;
	const gchar* _tmp0_ = NULL;
	self = _data2_->self;
	_tmp0_ = _data2_->data;
	test_do_something (self, _tmp0_);
	result = FALSE;
	return result;
}


static gboolean ___lambda5__gsource_func (gpointer self) {
	gboolean result;
	result = __lambda5_ (self);
	return result;
}


static gboolean _test_test_async_co_gsource_func (gpointer self) {
	gboolean result;
	result = test_test_async_co (self);
	return result;
}


static gboolean test_test_async_co (TestTestAsyncData* _data_) {
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_data2_ = g_slice_new0 (Block2Data);
	_data_->_data2_->_ref_count_ = 1;
	_data_->_data2_->self = g_object_ref (_data_->self);
	_data_->_tmp0_ = NULL;
	_data_->_tmp0_ = _data_->data;
	_g_free0 (_data_->_data2_->data);
	_data_->_data2_->data = _data_->_tmp0_;
	_data_->_data2_->_async_data_ = _data_;
	g_idle_add_full (G_PRIORITY_DEFAULT_IDLE, ___lambda5__gsource_func, block2_data_ref (_data_->_data2_), block2_data_unref);
	g_idle_add_full (G_PRIORITY_DEFAULT_IDLE, _test_test_async_co_gsource_func, _data_, NULL);
	block2_data_unref (_data_->_data2_);
	_data_->_data2_ = 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;
}


static void test_do_something (Test* self, const gchar* data) {
	FILE* _tmp0_ = NULL;
	const gchar* _tmp1_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (data != NULL);
	_tmp0_ = stdout;
	_tmp1_ = data;
	fprintf (_tmp0_, "%s\n", _tmp1_);
}


Test* test_construct (GType object_type) {
	Test * self = NULL;
	self = (Test*) g_object_new (object_type, NULL);
	return self;
}


Test* test_new (void) {
	return test_construct (TYPE_TEST);
}


static void test_class_init (TestClass * klass) {
	test_parent_class = g_type_class_peek_parent (klass);
}


static void test_instance_init (Test * self) {
}


GType test_get_type (void) {
	static volatile gsize test_type_id__volatile = 0;
	if (g_once_init_enter (&test_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (TestClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) test_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (Test), 0, (GInstanceInitFunc) test_instance_init, NULL };
		GType test_type_id;
		test_type_id = g_type_register_static (G_TYPE_OBJECT, "Test", &g_define_type_info, 0);
		g_once_init_leave (&test_type_id__volatile, test_type_id);
	}
	return test_type_id__volatile;
}


static Block3Data* block3_data_ref (Block3Data* _data3_) {
	g_atomic_int_inc (&_data3_->_ref_count_);
	return _data3_;
}


static void block3_data_unref (void * _userdata_) {
	Block3Data* _data3_;
	_data3_ = (Block3Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data3_->_ref_count_)) {
		_g_object_unref0 (_data3_->instance);
		g_slice_free (Block3Data, _data3_);
	}
}


static void __lambda6_ (Block3Data* _data3_, GObject* obj, GAsyncResult* res) {
	GAsyncResult* _tmp0_ = NULL;
	g_return_if_fail (res != NULL);
	_tmp0_ = res;
	test_test_finish (_data3_->instance, _tmp0_);
}


static void ___lambda6__gasync_ready_callback (GObject* source_object, GAsyncResult* res, gpointer self) {
	__lambda6_ (self, source_object, res);
	block3_data_unref (self);
}


gint _vala_main (gchar** argv, int argv_length1) {
	gint result = 0;
	Block3Data* _data3_;
	Test* _tmp0_ = NULL;
	GMainLoop* _tmp1_ = NULL;
	GMainLoop* _tmp2_ = NULL;
	_data3_ = g_slice_new0 (Block3Data);
	_data3_->_ref_count_ = 1;
	_tmp0_ = test_new ();
	_data3_->instance = _tmp0_;
	test_test_sync (_data3_->instance, "test sync");
	test_test_async (_data3_->instance, "test async", ___lambda6__gasync_ready_callback, block3_data_ref (_data3_));
	_tmp1_ = g_main_loop_new (NULL, FALSE);
	_tmp2_ = _tmp1_;
	g_main_loop_run (_tmp2_);
	_g_main_loop_unref0 (_tmp2_);
	result = 0;
	block3_data_unref (_data3_);
	_data3_ = NULL;
	return result;
}


int main (int argc, char ** argv) {
#if !GLIB_CHECK_VERSION (2,35,0)
	g_type_init ();
#endif
	return _vala_main (argv, argc);
}



