/* app-conversation-operation-queue.c generated by valac 0.56.19, the Vala compiler
 * generated from app-conversation-operation-queue.vala, do not modify */

/*
 * Copyright 2016 Software Freedom Conservancy Inc.
 *
 * This software is licensed under the GNU Lesser General Public License
 * (version 2.1 or later).  See the COPYING file in this distribution.
 */

#include "geary-engine.h"
#include <glib-object.h>
#include <glib.h>
#include <gee.h>
#include <gio/gio.h>
#include <stdlib.h>
#include <string.h>

#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif

#define GEARY_APP_TYPE_CONVERSATION_OPERATION_QUEUE (geary_app_conversation_operation_queue_get_type ())
#define GEARY_APP_CONVERSATION_OPERATION_QUEUE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEARY_APP_TYPE_CONVERSATION_OPERATION_QUEUE, GearyAppConversationOperationQueue))
#define GEARY_APP_CONVERSATION_OPERATION_QUEUE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GEARY_APP_TYPE_CONVERSATION_OPERATION_QUEUE, GearyAppConversationOperationQueueClass))
#define GEARY_APP_IS_CONVERSATION_OPERATION_QUEUE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEARY_APP_TYPE_CONVERSATION_OPERATION_QUEUE))
#define GEARY_APP_IS_CONVERSATION_OPERATION_QUEUE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEARY_APP_TYPE_CONVERSATION_OPERATION_QUEUE))
#define GEARY_APP_CONVERSATION_OPERATION_QUEUE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GEARY_APP_TYPE_CONVERSATION_OPERATION_QUEUE, GearyAppConversationOperationQueueClass))

typedef struct _GearyAppConversationOperationQueue GearyAppConversationOperationQueue;
typedef struct _GearyAppConversationOperationQueueClass GearyAppConversationOperationQueueClass;
typedef struct _GearyAppConversationOperationQueuePrivate GearyAppConversationOperationQueuePrivate;

#define GEARY_APP_TYPE_CONVERSATION_OPERATION (geary_app_conversation_operation_get_type ())
#define GEARY_APP_CONVERSATION_OPERATION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEARY_APP_TYPE_CONVERSATION_OPERATION, GearyAppConversationOperation))
#define GEARY_APP_CONVERSATION_OPERATION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GEARY_APP_TYPE_CONVERSATION_OPERATION, GearyAppConversationOperationClass))
#define GEARY_APP_IS_CONVERSATION_OPERATION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEARY_APP_TYPE_CONVERSATION_OPERATION))
#define GEARY_APP_IS_CONVERSATION_OPERATION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEARY_APP_TYPE_CONVERSATION_OPERATION))
#define GEARY_APP_CONVERSATION_OPERATION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GEARY_APP_TYPE_CONVERSATION_OPERATION, GearyAppConversationOperationClass))

typedef struct _GearyAppConversationOperation GearyAppConversationOperation;
typedef struct _GearyAppConversationOperationClass GearyAppConversationOperationClass;
enum  {
	GEARY_APP_CONVERSATION_OPERATION_QUEUE_0_PROPERTY,
	GEARY_APP_CONVERSATION_OPERATION_QUEUE_IS_PROCESSING_PROPERTY,
	GEARY_APP_CONVERSATION_OPERATION_QUEUE_PROGRESS_MONITOR_PROPERTY,
	GEARY_APP_CONVERSATION_OPERATION_QUEUE_NUM_PROPERTIES
};
static GParamSpec* geary_app_conversation_operation_queue_properties[GEARY_APP_CONVERSATION_OPERATION_QUEUE_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

#define GEARY_APP_TYPE_TERMINATE_OPERATION (geary_app_terminate_operation_get_type ())
#define GEARY_APP_TERMINATE_OPERATION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEARY_APP_TYPE_TERMINATE_OPERATION, GearyAppTerminateOperation))
#define GEARY_APP_TERMINATE_OPERATION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GEARY_APP_TYPE_TERMINATE_OPERATION, GearyAppTerminateOperationClass))
#define GEARY_APP_IS_TERMINATE_OPERATION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEARY_APP_TYPE_TERMINATE_OPERATION))
#define GEARY_APP_IS_TERMINATE_OPERATION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEARY_APP_TYPE_TERMINATE_OPERATION))
#define GEARY_APP_TERMINATE_OPERATION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GEARY_APP_TYPE_TERMINATE_OPERATION, GearyAppTerminateOperationClass))

typedef struct _GearyAppTerminateOperation GearyAppTerminateOperation;
typedef struct _GearyAppTerminateOperationClass GearyAppTerminateOperationClass;
typedef struct _GearyAppConversationOperationQueueStopProcessingAsyncData GearyAppConversationOperationQueueStopProcessingAsyncData;
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
typedef struct _GearyAppConversationOperationQueueRunProcessAsyncData GearyAppConversationOperationQueueRunProcessAsyncData;
enum  {
	GEARY_APP_CONVERSATION_OPERATION_QUEUE_OPERATION_ERROR_SIGNAL,
	GEARY_APP_CONVERSATION_OPERATION_QUEUE_NUM_SIGNALS
};
static guint geary_app_conversation_operation_queue_signals[GEARY_APP_CONVERSATION_OPERATION_QUEUE_NUM_SIGNALS] = {0};

struct _GearyAppConversationOperationQueue {
	GearyBaseObject parent_instance;
	GearyAppConversationOperationQueuePrivate * priv;
};

struct _GearyAppConversationOperationQueueClass {
	GearyBaseObjectClass parent_class;
};

struct _GearyAppConversationOperationQueuePrivate {
	gboolean _is_processing;
	GearyProgressMonitor* _progress_monitor;
	GearyNonblockingQueue* mailbox;
	GearyNonblockingSpinlock* processing_done_spinlock;
};

struct _GearyAppConversationOperationQueueStopProcessingAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyAppConversationOperationQueue* self;
	GCancellable* cancellable;
	gboolean _tmp0_;
	GearyAppTerminateOperation* _tmp1_;
	GearyAppTerminateOperation* _tmp2_;
	GearyNonblockingSpinlock* _tmp3_;
	GError* _inner_error0_;
};

struct _GearyAppConversationOperationQueueRunProcessAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyAppConversationOperationQueue* self;
	gboolean _tmp0_;
	GearyAppConversationOperation* op;
	GearyAppConversationOperation* _tmp1_;
	GearyNonblockingQueue* _tmp2_;
	gpointer _tmp3_;
	GearyAppConversationOperation* _tmp4_;
	GError* e;
	GError* _tmp5_;
	const gchar* _tmp6_;
	GearyAppConversationOperation* _tmp7_;
	GearyProgressMonitor* _tmp8_;
	gboolean _tmp9_;
	gboolean _tmp10_;
	GearyProgressMonitor* _tmp11_;
	GearyAppConversationOperation* _tmp12_;
	GError* err;
	GearyAppConversationOperation* _tmp13_;
	GError* _tmp14_;
	GearyNonblockingQueue* _tmp15_;
	gint _tmp16_;
	gint _tmp17_;
	GearyProgressMonitor* _tmp18_;
	GearyNonblockingSpinlock* _tmp19_;
	GError* _inner_error0_;
};

static gint GearyAppConversationOperationQueue_private_offset;
static gpointer geary_app_conversation_operation_queue_parent_class = NULL;

VALA_EXTERN GType geary_app_conversation_operation_queue_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GType geary_app_conversation_operation_get_type (void) G_GNUC_CONST ;
VALA_EXTERN gboolean geary_app_conversation_operation_queue_get_is_processing (GearyAppConversationOperationQueue* self);
static void geary_app_conversation_operation_queue_set_is_processing (GearyAppConversationOperationQueue* self,
                                                               gboolean value);
VALA_EXTERN GearyProgressMonitor* geary_app_conversation_operation_queue_get_progress_monitor (GearyAppConversationOperationQueue* self);
static void geary_app_conversation_operation_queue_set_progress_monitor (GearyAppConversationOperationQueue* self,
                                                                  GearyProgressMonitor* value);
static void g_cclosure_user_marshal_VOID__OBJECT_BOXED (GClosure * closure,
                                                 GValue * return_value,
                                                 guint n_param_values,
                                                 const GValue * param_values,
                                                 gpointer invocation_hint,
                                                 gpointer marshal_data);
VALA_EXTERN GearyAppConversationOperationQueue* geary_app_conversation_operation_queue_new (GearyProgressMonitor* progress);
VALA_EXTERN GearyAppConversationOperationQueue* geary_app_conversation_operation_queue_construct (GType object_type,
                                                                                      GearyProgressMonitor* progress);
VALA_EXTERN void geary_app_conversation_operation_queue_clear (GearyAppConversationOperationQueue* self);
VALA_EXTERN void geary_app_conversation_operation_queue_add (GearyAppConversationOperationQueue* self,
                                                 GearyAppConversationOperation* op);
VALA_EXTERN gboolean geary_app_conversation_operation_get_allow_duplicates (GearyAppConversationOperation* self);
static void geary_app_conversation_operation_queue_stop_processing_async_data_free (gpointer _data);
VALA_EXTERN void geary_app_conversation_operation_queue_stop_processing_async (GearyAppConversationOperationQueue* self,
                                                                   GCancellable* cancellable,
                                                                   GAsyncReadyCallback _callback_,
                                                                   gpointer _user_data_);
VALA_EXTERN void geary_app_conversation_operation_queue_stop_processing_finish (GearyAppConversationOperationQueue* self,
                                                                    GAsyncResult* _res_,
                                                                    GError** error);
static gboolean geary_app_conversation_operation_queue_stop_processing_async_co (GearyAppConversationOperationQueueStopProcessingAsyncData* _data_);
VALA_EXTERN GearyAppTerminateOperation* geary_app_terminate_operation_new (void);
VALA_EXTERN GearyAppTerminateOperation* geary_app_terminate_operation_construct (GType object_type);
VALA_EXTERN GType geary_app_terminate_operation_get_type (void) G_GNUC_CONST ;
static void geary_app_conversation_operation_queue_stop_processing_async_ready (GObject* source_object,
                                                                         GAsyncResult* _res_,
                                                                         gpointer _user_data_);
static void geary_app_conversation_operation_queue_run_process_async_data_free (gpointer _data);
VALA_EXTERN void geary_app_conversation_operation_queue_run_process_async (GearyAppConversationOperationQueue* self,
                                                               GAsyncReadyCallback _callback_,
                                                               gpointer _user_data_);
VALA_EXTERN void geary_app_conversation_operation_queue_run_process_finish (GearyAppConversationOperationQueue* self,
                                                                GAsyncResult* _res_);
static gboolean geary_app_conversation_operation_queue_run_process_async_co (GearyAppConversationOperationQueueRunProcessAsyncData* _data_);
static void geary_app_conversation_operation_queue_run_process_async_ready (GObject* source_object,
                                                                     GAsyncResult* _res_,
                                                                     gpointer _user_data_);
VALA_EXTERN void geary_app_conversation_operation_execute_async (GearyAppConversationOperation* self,
                                                     GAsyncReadyCallback _callback_,
                                                     gpointer _user_data_);
VALA_EXTERN void geary_app_conversation_operation_execute_finish (GearyAppConversationOperation* self,
                                                      GAsyncResult* _res_,
                                                      GError** error);
static void geary_app_conversation_operation_queue_finalize (GObject * obj);
static GType geary_app_conversation_operation_queue_get_type_once (void);
static void _vala_geary_app_conversation_operation_queue_get_property (GObject * object,
                                                                guint property_id,
                                                                GValue * value,
                                                                GParamSpec * pspec);
static void _vala_geary_app_conversation_operation_queue_set_property (GObject * object,
                                                                guint property_id,
                                                                const GValue * value,
                                                                GParamSpec * pspec);

static inline gpointer
geary_app_conversation_operation_queue_get_instance_private (GearyAppConversationOperationQueue* self)
{
	return G_STRUCT_MEMBER_P (self, GearyAppConversationOperationQueue_private_offset);
}

gboolean
geary_app_conversation_operation_queue_get_is_processing (GearyAppConversationOperationQueue* self)
{
	gboolean result;
	g_return_val_if_fail (GEARY_APP_IS_CONVERSATION_OPERATION_QUEUE (self), FALSE);
	result = self->priv->_is_processing;
	return result;
}

static void
geary_app_conversation_operation_queue_set_is_processing (GearyAppConversationOperationQueue* self,
                                                          gboolean value)
{
	gboolean old_value;
	g_return_if_fail (GEARY_APP_IS_CONVERSATION_OPERATION_QUEUE (self));
	old_value = geary_app_conversation_operation_queue_get_is_processing (self);
	if (old_value != value) {
		self->priv->_is_processing = value;
		g_object_notify_by_pspec ((GObject *) self, geary_app_conversation_operation_queue_properties[GEARY_APP_CONVERSATION_OPERATION_QUEUE_IS_PROCESSING_PROPERTY]);
	}
}

GearyProgressMonitor*
geary_app_conversation_operation_queue_get_progress_monitor (GearyAppConversationOperationQueue* self)
{
	GearyProgressMonitor* result;
	GearyProgressMonitor* _tmp0_;
	g_return_val_if_fail (GEARY_APP_IS_CONVERSATION_OPERATION_QUEUE (self), NULL);
	_tmp0_ = self->priv->_progress_monitor;
	result = _tmp0_;
	return result;
}

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

static void
geary_app_conversation_operation_queue_set_progress_monitor (GearyAppConversationOperationQueue* self,
                                                             GearyProgressMonitor* value)
{
	GearyProgressMonitor* old_value;
	g_return_if_fail (GEARY_APP_IS_CONVERSATION_OPERATION_QUEUE (self));
	old_value = geary_app_conversation_operation_queue_get_progress_monitor (self);
	if (old_value != value) {
		GearyProgressMonitor* _tmp0_;
		_tmp0_ = _g_object_ref0 (value);
		_g_object_unref0 (self->priv->_progress_monitor);
		self->priv->_progress_monitor = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, geary_app_conversation_operation_queue_properties[GEARY_APP_CONVERSATION_OPERATION_QUEUE_PROGRESS_MONITOR_PROPERTY]);
	}
}

static void
g_cclosure_user_marshal_VOID__OBJECT_BOXED (GClosure * closure,
                                            GValue * return_value,
                                            guint n_param_values,
                                            const GValue * param_values,
                                            gpointer invocation_hint,
                                            gpointer marshal_data)
{
	typedef void (*GMarshalFunc_VOID__OBJECT_BOXED) (gpointer data1, gpointer arg_1, gpointer arg_2, gpointer data2);
	register GMarshalFunc_VOID__OBJECT_BOXED callback;
	register GCClosure * cc;
	register gpointer data1;
	register gpointer data2;
	cc = (GCClosure *) closure;
	g_return_if_fail (n_param_values == 3);
	if (G_CCLOSURE_SWAP_DATA (closure)) {
		data1 = closure->data;
		data2 = param_values->data[0].v_pointer;
	} else {
		data1 = param_values->data[0].v_pointer;
		data2 = closure->data;
	}
	callback = (GMarshalFunc_VOID__OBJECT_BOXED) (marshal_data ? marshal_data : cc->callback);
	callback (data1, g_value_get_object (param_values + 1), g_value_get_boxed (param_values + 2), data2);
}

GearyAppConversationOperationQueue*
geary_app_conversation_operation_queue_construct (GType object_type,
                                                  GearyProgressMonitor* progress)
{
	GearyAppConversationOperationQueue * self = NULL;
	g_return_val_if_fail (GEARY_IS_PROGRESS_MONITOR (progress), NULL);
	self = (GearyAppConversationOperationQueue*) geary_base_object_construct (object_type);
	geary_app_conversation_operation_queue_set_progress_monitor (self, progress);
	return self;
}

GearyAppConversationOperationQueue*
geary_app_conversation_operation_queue_new (GearyProgressMonitor* progress)
{
	return geary_app_conversation_operation_queue_construct (GEARY_APP_TYPE_CONVERSATION_OPERATION_QUEUE, progress);
}

void
geary_app_conversation_operation_queue_clear (GearyAppConversationOperationQueue* self)
{
	GearyNonblockingQueue* _tmp0_;
	g_return_if_fail (GEARY_APP_IS_CONVERSATION_OPERATION_QUEUE (self));
	_tmp0_ = self->priv->mailbox;
	geary_nonblocking_queue_clear (_tmp0_);
}

void
geary_app_conversation_operation_queue_add (GearyAppConversationOperationQueue* self,
                                            GearyAppConversationOperation* op)
{
	gboolean add_op = FALSE;
	gboolean _tmp0_;
	gboolean _tmp1_;
	g_return_if_fail (GEARY_APP_IS_CONVERSATION_OPERATION_QUEUE (self));
	g_return_if_fail (GEARY_APP_IS_CONVERSATION_OPERATION (op));
	add_op = TRUE;
	_tmp0_ = geary_app_conversation_operation_get_allow_duplicates (op);
	_tmp1_ = _tmp0_;
	if (!_tmp1_) {
		GType op_type = G_TYPE_NONE;
		op_type = G_TYPE_FROM_INSTANCE (G_TYPE_CHECK_INSTANCE_CAST (op, G_TYPE_OBJECT, GObject));
		{
			GeeIterator* _other_it = NULL;
			GearyNonblockingQueue* _tmp2_;
			GeeCollection* _tmp3_;
			GeeCollection* _tmp4_;
			GeeIterator* _tmp5_;
			GeeIterator* _tmp6_;
			_tmp2_ = self->priv->mailbox;
			_tmp3_ = geary_nonblocking_queue_get_all (_tmp2_);
			_tmp4_ = _tmp3_;
			_tmp5_ = gee_iterable_iterator (G_TYPE_CHECK_INSTANCE_CAST (_tmp4_, GEE_TYPE_ITERABLE, GeeIterable));
			_tmp6_ = _tmp5_;
			_g_object_unref0 (_tmp4_);
			_other_it = _tmp6_;
			while (TRUE) {
				GeeIterator* _tmp7_;
				GearyAppConversationOperation* other = NULL;
				GeeIterator* _tmp8_;
				gpointer _tmp9_;
				GearyAppConversationOperation* _tmp10_;
				_tmp7_ = _other_it;
				if (!gee_iterator_next (_tmp7_)) {
					break;
				}
				_tmp8_ = _other_it;
				_tmp9_ = gee_iterator_get (_tmp8_);
				other = (GearyAppConversationOperation*) _tmp9_;
				_tmp10_ = other;
				if (G_TYPE_FROM_INSTANCE (G_TYPE_CHECK_INSTANCE_CAST (_tmp10_, G_TYPE_OBJECT, GObject)) == op_type) {
					add_op = FALSE;
					_g_object_unref0 (other);
					break;
				}
				_g_object_unref0 (other);
			}
			_g_object_unref0 (_other_it);
		}
	}
	if (add_op) {
		GearyNonblockingQueue* _tmp11_;
		_tmp11_ = self->priv->mailbox;
		geary_nonblocking_queue_send (_tmp11_, op);
	}
}

static void
geary_app_conversation_operation_queue_stop_processing_async_data_free (gpointer _data)
{
	GearyAppConversationOperationQueueStopProcessingAsyncData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->cancellable);
	_g_object_unref0 (_data_->self);
	g_slice_free (GearyAppConversationOperationQueueStopProcessingAsyncData, _data_);
}

void
geary_app_conversation_operation_queue_stop_processing_async (GearyAppConversationOperationQueue* self,
                                                              GCancellable* cancellable,
                                                              GAsyncReadyCallback _callback_,
                                                              gpointer _user_data_)
{
	GearyAppConversationOperationQueueStopProcessingAsyncData* _data_;
	GearyAppConversationOperationQueue* _tmp0_;
	GCancellable* _tmp1_;
	g_return_if_fail (GEARY_APP_IS_CONVERSATION_OPERATION_QUEUE (self));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	_data_ = g_slice_new0 (GearyAppConversationOperationQueueStopProcessingAsyncData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_app_conversation_operation_queue_stop_processing_async_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp1_;
	geary_app_conversation_operation_queue_stop_processing_async_co (_data_);
}

void
geary_app_conversation_operation_queue_stop_processing_finish (GearyAppConversationOperationQueue* self,
                                                               GAsyncResult* _res_,
                                                               GError** error)
{
	GearyAppConversationOperationQueueStopProcessingAsyncData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return;
	}
}

static void
geary_app_conversation_operation_queue_stop_processing_async_ready (GObject* source_object,
                                                                    GAsyncResult* _res_,
                                                                    gpointer _user_data_)
{
	GearyAppConversationOperationQueueStopProcessingAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_app_conversation_operation_queue_stop_processing_async_co (_data_);
}

static gboolean
geary_app_conversation_operation_queue_stop_processing_async_co (GearyAppConversationOperationQueueStopProcessingAsyncData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = _data_->self->priv->_is_processing;
	if (_data_->_tmp0_) {
		geary_app_conversation_operation_queue_clear (_data_->self);
		_data_->_tmp1_ = geary_app_terminate_operation_new ();
		_data_->_tmp2_ = _data_->_tmp1_;
		geary_app_conversation_operation_queue_add (_data_->self, G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp2_, GEARY_APP_TYPE_CONVERSATION_OPERATION, GearyAppConversationOperation));
		_g_object_unref0 (_data_->_tmp2_);
		_data_->_tmp3_ = _data_->self->priv->processing_done_spinlock;
		_data_->_state_ = 1;
		geary_nonblocking_lock_wait_async (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp3_, GEARY_NONBLOCKING_TYPE_LOCK, GearyNonblockingLock), _data_->cancellable, geary_app_conversation_operation_queue_stop_processing_async_ready, _data_);
		return FALSE;
		_state_1:
		geary_nonblocking_lock_wait_finish (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp3_, GEARY_NONBLOCKING_TYPE_LOCK, GearyNonblockingLock), _data_->_res_, &_data_->_inner_error0_);
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
	}
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

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

void
geary_app_conversation_operation_queue_run_process_async (GearyAppConversationOperationQueue* self,
                                                          GAsyncReadyCallback _callback_,
                                                          gpointer _user_data_)
{
	GearyAppConversationOperationQueueRunProcessAsyncData* _data_;
	GearyAppConversationOperationQueue* _tmp0_;
	g_return_if_fail (GEARY_APP_IS_CONVERSATION_OPERATION_QUEUE (self));
	_data_ = g_slice_new0 (GearyAppConversationOperationQueueRunProcessAsyncData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_app_conversation_operation_queue_run_process_async_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	geary_app_conversation_operation_queue_run_process_async_co (_data_);
}

void
geary_app_conversation_operation_queue_run_process_finish (GearyAppConversationOperationQueue* self,
                                                           GAsyncResult* _res_)
{
	GearyAppConversationOperationQueueRunProcessAsyncData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
}

static void
geary_app_conversation_operation_queue_run_process_async_ready (GObject* source_object,
                                                                GAsyncResult* _res_,
                                                                gpointer _user_data_)
{
	GearyAppConversationOperationQueueRunProcessAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_app_conversation_operation_queue_run_process_async_co (_data_);
}

static gboolean
geary_app_conversation_operation_queue_run_process_async_co (GearyAppConversationOperationQueueRunProcessAsyncData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		case 2:
		goto _state_2;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	geary_app_conversation_operation_queue_set_is_processing (_data_->self, TRUE);
	{
		_data_->_tmp0_ = TRUE;
		while (TRUE) {
			if (!_data_->_tmp0_) {
			}
			_data_->_tmp0_ = FALSE;
			{
				_data_->_tmp2_ = _data_->self->priv->mailbox;
				_data_->_state_ = 1;
				geary_nonblocking_queue_receive (_data_->_tmp2_, NULL, geary_app_conversation_operation_queue_run_process_async_ready, _data_);
				return FALSE;
				_state_1:
				_data_->_tmp3_ = geary_nonblocking_queue_receive_finish (_data_->_tmp2_, _data_->_res_, &_data_->_inner_error0_);
				_data_->_tmp1_ = (GearyAppConversationOperation*) _data_->_tmp3_;
				if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
					goto __catch0_g_error;
				}
				_data_->_tmp4_ = _data_->_tmp1_;
				_data_->_tmp1_ = NULL;
				_g_object_unref0 (_data_->op);
				_data_->op = _data_->_tmp4_;
				_g_object_unref0 (_data_->_tmp1_);
			}
			goto __finally0;
			__catch0_g_error:
			{
				_data_->e = _data_->_inner_error0_;
				_data_->_inner_error0_ = NULL;
				_data_->_tmp5_ = _data_->e;
				_data_->_tmp6_ = _data_->_tmp5_->message;
				g_debug ("app-conversation-operation-queue.vala:65: Error processing in conversa" \
"tion operation mailbox: %s", _data_->_tmp6_);
				_g_error_free0 (_data_->e);
				_g_object_unref0 (_data_->op);
				break;
			}
			__finally0:
			if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
				_g_object_unref0 (_data_->op);
				g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
				g_clear_error (&_data_->_inner_error0_);
				g_object_unref (_data_->_async_result);
				return FALSE;
			}
			_data_->_tmp7_ = _data_->op;
			if (GEARY_APP_IS_TERMINATE_OPERATION (_data_->_tmp7_)) {
				_g_object_unref0 (_data_->op);
				break;
			}
			_data_->_tmp8_ = _data_->self->priv->_progress_monitor;
			_data_->_tmp9_ = geary_progress_monitor_get_is_in_progress (_data_->_tmp8_);
			_data_->_tmp10_ = _data_->_tmp9_;
			if (!_data_->_tmp10_) {
				_data_->_tmp11_ = _data_->self->priv->_progress_monitor;
				geary_progress_monitor_notify_start (_data_->_tmp11_);
			}
			{
				_data_->_tmp12_ = _data_->op;
				_data_->_state_ = 2;
				geary_app_conversation_operation_execute_async (_data_->_tmp12_, geary_app_conversation_operation_queue_run_process_async_ready, _data_);
				return FALSE;
				_state_2:
				geary_app_conversation_operation_execute_finish (_data_->_tmp12_, _data_->_res_, &_data_->_inner_error0_);
				if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
					goto __catch1_g_error;
				}
			}
			goto __finally1;
			__catch1_g_error:
			{
				_data_->err = _data_->_inner_error0_;
				_data_->_inner_error0_ = NULL;
				_data_->_tmp13_ = _data_->op;
				_data_->_tmp14_ = _data_->err;
				g_signal_emit (_data_->self, geary_app_conversation_operation_queue_signals[GEARY_APP_CONVERSATION_OPERATION_QUEUE_OPERATION_ERROR_SIGNAL], 0, _data_->_tmp13_, _data_->_tmp14_);
				_g_error_free0 (_data_->err);
			}
			__finally1:
			if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
				_g_object_unref0 (_data_->op);
				g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
				g_clear_error (&_data_->_inner_error0_);
				g_object_unref (_data_->_async_result);
				return FALSE;
			}
			_data_->_tmp15_ = _data_->self->priv->mailbox;
			_data_->_tmp16_ = geary_nonblocking_queue_get_size (_data_->_tmp15_);
			_data_->_tmp17_ = _data_->_tmp16_;
			if (_data_->_tmp17_ == 0) {
				_data_->_tmp18_ = _data_->self->priv->_progress_monitor;
				geary_progress_monitor_notify_finish (_data_->_tmp18_);
			}
			_g_object_unref0 (_data_->op);
		}
	}
	geary_app_conversation_operation_queue_set_is_processing (_data_->self, FALSE);
	_data_->_tmp19_ = _data_->self->priv->processing_done_spinlock;
	geary_nonblocking_lock_blind_notify (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp19_, GEARY_NONBLOCKING_TYPE_LOCK, GearyNonblockingLock));
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static void
geary_app_conversation_operation_queue_class_init (GearyAppConversationOperationQueueClass * klass,
                                                   gpointer klass_data)
{
	geary_app_conversation_operation_queue_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &GearyAppConversationOperationQueue_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_geary_app_conversation_operation_queue_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_geary_app_conversation_operation_queue_set_property;
	G_OBJECT_CLASS (klass)->finalize = geary_app_conversation_operation_queue_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), GEARY_APP_CONVERSATION_OPERATION_QUEUE_IS_PROCESSING_PROPERTY, geary_app_conversation_operation_queue_properties[GEARY_APP_CONVERSATION_OPERATION_QUEUE_IS_PROCESSING_PROPERTY] = g_param_spec_boolean ("is-processing", "is-processing", "is-processing", FALSE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	/** Tracks progress running operations in this queue. */
	g_object_class_install_property (G_OBJECT_CLASS (klass), GEARY_APP_CONVERSATION_OPERATION_QUEUE_PROGRESS_MONITOR_PROPERTY, geary_app_conversation_operation_queue_properties[GEARY_APP_CONVERSATION_OPERATION_QUEUE_PROGRESS_MONITOR_PROPERTY] = g_param_spec_object ("progress-monitor", "progress-monitor", "progress-monitor", GEARY_TYPE_PROGRESS_MONITOR, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	/** Fired when an error occurs executing an operation. */
	geary_app_conversation_operation_queue_signals[GEARY_APP_CONVERSATION_OPERATION_QUEUE_OPERATION_ERROR_SIGNAL] = g_signal_new ("operation-error", GEARY_APP_TYPE_CONVERSATION_OPERATION_QUEUE, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_user_marshal_VOID__OBJECT_BOXED, G_TYPE_NONE, 2, GEARY_APP_TYPE_CONVERSATION_OPERATION, G_TYPE_ERROR);
}

static void
geary_app_conversation_operation_queue_instance_init (GearyAppConversationOperationQueue * self,
                                                      gpointer klass)
{
	GearyNonblockingQueue* _tmp0_;
	GearyNonblockingSpinlock* _tmp1_;
	self->priv = geary_app_conversation_operation_queue_get_instance_private (self);
	self->priv->_is_processing = FALSE;
	_tmp0_ = geary_nonblocking_queue_new_fifo (GEARY_APP_TYPE_CONVERSATION_OPERATION, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
	self->priv->mailbox = _tmp0_;
	_tmp1_ = geary_nonblocking_spinlock_new (NULL);
	self->priv->processing_done_spinlock = _tmp1_;
}

static void
geary_app_conversation_operation_queue_finalize (GObject * obj)
{
	GearyAppConversationOperationQueue * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GEARY_APP_TYPE_CONVERSATION_OPERATION_QUEUE, GearyAppConversationOperationQueue);
	_g_object_unref0 (self->priv->_progress_monitor);
	_g_object_unref0 (self->priv->mailbox);
	_g_object_unref0 (self->priv->processing_done_spinlock);
	G_OBJECT_CLASS (geary_app_conversation_operation_queue_parent_class)->finalize (obj);
}

 G_GNUC_NO_INLINE static GType
geary_app_conversation_operation_queue_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GearyAppConversationOperationQueueClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) geary_app_conversation_operation_queue_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GearyAppConversationOperationQueue), 0, (GInstanceInitFunc) geary_app_conversation_operation_queue_instance_init, NULL };
	GType geary_app_conversation_operation_queue_type_id;
	geary_app_conversation_operation_queue_type_id = g_type_register_static (GEARY_TYPE_BASE_OBJECT, "GearyAppConversationOperationQueue", &g_define_type_info, 0);
	GearyAppConversationOperationQueue_private_offset = g_type_add_instance_private (geary_app_conversation_operation_queue_type_id, sizeof (GearyAppConversationOperationQueuePrivate));
	return geary_app_conversation_operation_queue_type_id;
}

GType
geary_app_conversation_operation_queue_get_type (void)
{
	static gsize geary_app_conversation_operation_queue_type_id__once = 0;
	if (g_once_init_enter (&geary_app_conversation_operation_queue_type_id__once)) {
		GType geary_app_conversation_operation_queue_type_id;
		geary_app_conversation_operation_queue_type_id = geary_app_conversation_operation_queue_get_type_once ();
		g_once_init_leave (&geary_app_conversation_operation_queue_type_id__once, geary_app_conversation_operation_queue_type_id);
	}
	return geary_app_conversation_operation_queue_type_id__once;
}

static void
_vala_geary_app_conversation_operation_queue_get_property (GObject * object,
                                                           guint property_id,
                                                           GValue * value,
                                                           GParamSpec * pspec)
{
	GearyAppConversationOperationQueue * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GEARY_APP_TYPE_CONVERSATION_OPERATION_QUEUE, GearyAppConversationOperationQueue);
	switch (property_id) {
		case GEARY_APP_CONVERSATION_OPERATION_QUEUE_IS_PROCESSING_PROPERTY:
		g_value_set_boolean (value, geary_app_conversation_operation_queue_get_is_processing (self));
		break;
		case GEARY_APP_CONVERSATION_OPERATION_QUEUE_PROGRESS_MONITOR_PROPERTY:
		g_value_set_object (value, geary_app_conversation_operation_queue_get_progress_monitor (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_geary_app_conversation_operation_queue_set_property (GObject * object,
                                                           guint property_id,
                                                           const GValue * value,
                                                           GParamSpec * pspec)
{
	GearyAppConversationOperationQueue * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GEARY_APP_TYPE_CONVERSATION_OPERATION_QUEUE, GearyAppConversationOperationQueue);
	switch (property_id) {
		case GEARY_APP_CONVERSATION_OPERATION_QUEUE_IS_PROCESSING_PROPERTY:
		geary_app_conversation_operation_queue_set_is_processing (self, g_value_get_boolean (value));
		break;
		case GEARY_APP_CONVERSATION_OPERATION_QUEUE_PROGRESS_MONITOR_PROPERTY:
		geary_app_conversation_operation_queue_set_progress_monitor (self, g_value_get_object (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

