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

/*
 * This file is part of gedit-code-assistant.
 *
 * Copyright (C) 2011 - Jesse van den Kieboom
 *
 * gedit-code-assistant is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * gedit-code-assistant 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with gedit-code-assistant.  If not, see <http://www.gnu.org/licenses/>.
 */

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

typedef struct _Block1Data Block1Data;
typedef struct _GcpAsyncInThreadData GcpAsyncInThreadData;

typedef void (*GcpAsyncInThreadCallback) (void* user_data);
struct _Block1Data {
	int _ref_count_;
	GSourceFunc callback;
	gpointer callback_target;
	GDestroyNotify callback_target_destroy_notify;
	GcpAsyncInThreadCallback cb;
	gpointer cb_target;
	gpointer _async_data_;
};

struct _GcpAsyncInThreadData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GSimpleAsyncResult* _async_result;
	GcpAsyncInThreadCallback cb;
	gpointer cb_target;
	gboolean result;
	Block1Data* _data1_;
	GcpAsyncInThreadCallback _tmp0_;
	void* _tmp0__target;
	GThreadFunc run;
	void* run_target;
	GDestroyNotify run_target_destroy_notify;
	GError * _inner_error_;
};



static void gcp_async_in_thread_data_free (gpointer _data);
void gcp_async_in_thread (GcpAsyncInThreadCallback cb, void* cb_target, GAsyncReadyCallback _callback_, gpointer _user_data_);
gboolean gcp_async_in_thread_finish (GAsyncResult* _res_);
static gboolean gcp_async_in_thread_co (GcpAsyncInThreadData* _data_);
static Block1Data* block1_data_ref (Block1Data* _data1_);
static void block1_data_unref (void * _userdata_);
static gboolean _gcp_async_in_thread_co_gsource_func (gpointer self);
static void* __lambda2_ (Block1Data* _data1_);
static gpointer ___lambda2__gthread_func (gpointer self);


static void gcp_async_in_thread_data_free (gpointer _data) {
	GcpAsyncInThreadData* _data_;
	_data_ = _data;
	g_slice_free (GcpAsyncInThreadData, _data_);
}


void gcp_async_in_thread (GcpAsyncInThreadCallback cb, void* cb_target, GAsyncReadyCallback _callback_, gpointer _user_data_) {
	GcpAsyncInThreadData* _data_;
	GcpAsyncInThreadCallback _tmp0_;
	void* _tmp0__target;
	_data_ = g_slice_new0 (GcpAsyncInThreadData);
	_data_->_async_result = g_simple_async_result_new (g_object_newv (G_TYPE_OBJECT, 0, NULL), _callback_, _user_data_, gcp_async_in_thread);
	g_simple_async_result_set_op_res_gpointer (_data_->_async_result, _data_, gcp_async_in_thread_data_free);
	_tmp0_ = cb;
	_tmp0__target = cb_target;
	_data_->cb = _tmp0_;
	_data_->cb_target = _tmp0__target;
	gcp_async_in_thread_co (_data_);
}


gboolean gcp_async_in_thread_finish (GAsyncResult* _res_) {
	gboolean result;
	GcpAsyncInThreadData* _data_;
	_data_ = g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (_res_));
	result = _data_->result;
	return result;
}


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_)) {
		(_data1_->callback_target_destroy_notify == NULL) ? NULL : (_data1_->callback_target_destroy_notify (_data1_->callback_target), NULL);
		_data1_->callback = NULL;
		_data1_->callback_target = NULL;
		_data1_->callback_target_destroy_notify = NULL;
		g_slice_free (Block1Data, _data1_);
	}
}


static gboolean _gcp_async_in_thread_co_gsource_func (gpointer self) {
	gboolean result;
	result = gcp_async_in_thread_co (self);
	return result;
}


static void* __lambda2_ (Block1Data* _data1_) {
	void* result = NULL;
	GcpAsyncInThreadCallback _tmp0_;
	void* _tmp0__target;
	GSourceFunc _tmp1_;
	void* _tmp1__target;
	GDestroyNotify _tmp1__target_destroy_notify;
	_tmp0_ = _data1_->cb;
	_tmp0__target = _data1_->cb_target;
	_tmp0_ (_tmp0__target);
	_tmp1_ = _data1_->callback;
	_tmp1__target = _data1_->callback_target;
	_tmp1__target_destroy_notify = _data1_->callback_target_destroy_notify;
	_data1_->callback_target_destroy_notify = NULL;
	g_idle_add_full (G_PRIORITY_DEFAULT_IDLE, _tmp1_, _tmp1__target, _tmp1__target_destroy_notify);
	result = NULL;
	return result;
}


static gpointer ___lambda2__gthread_func (gpointer self) {
	gpointer result;
	result = __lambda2_ (self);
	return result;
}


static gboolean gcp_async_in_thread_co (GcpAsyncInThreadData* _data_) {
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_data1_ = g_slice_new0 (Block1Data);
	_data_->_data1_->_ref_count_ = 1;
	_data_->_tmp0_ = _data_->cb;
	_data_->_tmp0__target = _data_->cb_target;
	_data_->_data1_->cb = _data_->_tmp0_;
	_data_->_data1_->cb_target = _data_->_tmp0__target;
	_data_->_data1_->_async_data_ = _data_;
	_data_->_data1_->callback = _gcp_async_in_thread_co_gsource_func;
	_data_->_data1_->callback_target = _data_;
	_data_->_data1_->callback_target_destroy_notify = NULL;
	_data_->run = ___lambda2__gthread_func;
	_data_->run_target = block1_data_ref (_data_->_data1_);
	_data_->run_target_destroy_notify = block1_data_unref;
	{
		g_thread_create (_data_->run, _data_->run_target, FALSE, &_data_->_inner_error_);
		if (_data_->_inner_error_ != NULL) {
			goto __catch0_g_error;
		}
		_data_->_state_ = 1;
		return FALSE;
		_state_1:
		;
		_data_->result = TRUE;
		(_data_->run_target_destroy_notify == NULL) ? NULL : (_data_->run_target_destroy_notify (_data_->run_target), NULL);
		_data_->run = NULL;
		_data_->run_target = NULL;
		_data_->run_target_destroy_notify = NULL;
		block1_data_unref (_data_->_data1_);
		_data_->_data1_ = 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;
	}
	goto __finally0;
	__catch0_g_error:
	{
		g_clear_error (&_data_->_inner_error_);
		_data_->_inner_error_ = NULL;
		_data_->result = FALSE;
		(_data_->run_target_destroy_notify == NULL) ? NULL : (_data_->run_target_destroy_notify (_data_->run_target), NULL);
		_data_->run = NULL;
		_data_->run_target = NULL;
		_data_->run_target_destroy_notify = NULL;
		block1_data_unref (_data_->_data1_);
		_data_->_data1_ = 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;
	}
	__finally0:
	(_data_->run_target_destroy_notify == NULL) ? NULL : (_data_->run_target_destroy_notify (_data_->run_target), NULL);
	_data_->run = NULL;
	_data_->run_target = NULL;
	_data_->run_target_destroy_notify = NULL;
	block1_data_unref (_data_->_data1_);
	_data_->_data1_ = NULL;
	g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error_->message, g_quark_to_string (_data_->_inner_error_->domain), _data_->_inner_error_->code);
	g_clear_error (&_data_->_inner_error_);
	return FALSE;
	(_data_->run_target_destroy_notify == NULL) ? NULL : (_data_->run_target_destroy_notify (_data_->run_target), NULL);
	_data_->run = NULL;
	_data_->run_target = NULL;
	_data_->run_target_destroy_notify = NULL;
	block1_data_unref (_data_->_data1_);
	_data_->_data1_ = 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;
}



