/* app-mark-operation.c generated by valac 0.56.3, the Vala compiler
 * generated from app-mark-operation.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 <gio/gio.h>
#include <gee.h>
#include <glib.h>

#define GEARY_APP_TYPE_ASYNC_FOLDER_OPERATION (geary_app_async_folder_operation_get_type ())
#define GEARY_APP_ASYNC_FOLDER_OPERATION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEARY_APP_TYPE_ASYNC_FOLDER_OPERATION, GearyAppAsyncFolderOperation))
#define GEARY_APP_ASYNC_FOLDER_OPERATION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GEARY_APP_TYPE_ASYNC_FOLDER_OPERATION, GearyAppAsyncFolderOperationClass))
#define GEARY_APP_IS_ASYNC_FOLDER_OPERATION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEARY_APP_TYPE_ASYNC_FOLDER_OPERATION))
#define GEARY_APP_IS_ASYNC_FOLDER_OPERATION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEARY_APP_TYPE_ASYNC_FOLDER_OPERATION))
#define GEARY_APP_ASYNC_FOLDER_OPERATION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GEARY_APP_TYPE_ASYNC_FOLDER_OPERATION, GearyAppAsyncFolderOperationClass))

typedef struct _GearyAppAsyncFolderOperation GearyAppAsyncFolderOperation;
typedef struct _GearyAppAsyncFolderOperationClass GearyAppAsyncFolderOperationClass;
typedef struct _GearyAppAsyncFolderOperationPrivate GearyAppAsyncFolderOperationPrivate;

#define GEARY_APP_TYPE_MARK_OPERATION (geary_app_mark_operation_get_type ())
#define GEARY_APP_MARK_OPERATION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEARY_APP_TYPE_MARK_OPERATION, GearyAppMarkOperation))
#define GEARY_APP_MARK_OPERATION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GEARY_APP_TYPE_MARK_OPERATION, GearyAppMarkOperationClass))
#define GEARY_APP_IS_MARK_OPERATION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEARY_APP_TYPE_MARK_OPERATION))
#define GEARY_APP_IS_MARK_OPERATION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEARY_APP_TYPE_MARK_OPERATION))
#define GEARY_APP_MARK_OPERATION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GEARY_APP_TYPE_MARK_OPERATION, GearyAppMarkOperationClass))

typedef struct _GearyAppMarkOperation GearyAppMarkOperation;
typedef struct _GearyAppMarkOperationClass GearyAppMarkOperationClass;
typedef struct _GearyAppMarkOperationPrivate GearyAppMarkOperationPrivate;
enum  {
	GEARY_APP_MARK_OPERATION_0_PROPERTY,
	GEARY_APP_MARK_OPERATION_FOLDER_TYPE_PROPERTY,
	GEARY_APP_MARK_OPERATION_NUM_PROPERTIES
};
static GParamSpec* geary_app_mark_operation_properties[GEARY_APP_MARK_OPERATION_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef struct _GearyAppMarkOperationExecuteAsyncData GearyAppMarkOperationExecuteAsyncData;
#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);
#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; }
#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; }
#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);

struct _GearyAppAsyncFolderOperation {
	GearyBaseObject parent_instance;
	GearyAppAsyncFolderOperationPrivate * priv;
};

struct _GearyAppAsyncFolderOperationClass {
	GearyBaseObjectClass parent_class;
	GType (*get_folder_type) (GearyAppAsyncFolderOperation* self);
	void (*execute_async) (GearyAppAsyncFolderOperation* self, GearyFolder* folder, GeeCollection* ids, GCancellable* cancellable, GAsyncReadyCallback _callback_, gpointer _user_data_);
	GeeCollection* (*execute_finish) (GearyAppAsyncFolderOperation* self, GAsyncResult* _res_, GError** error);
};

struct _GearyAppMarkOperation {
	GearyAppAsyncFolderOperation parent_instance;
	GearyEmailFlags* flags_to_add;
	GearyEmailFlags* flags_to_remove;
	GearyAppMarkOperationPrivate * priv;
};

struct _GearyAppMarkOperationClass {
	GearyAppAsyncFolderOperationClass parent_class;
};

struct _GearyAppMarkOperationExecuteAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyAppMarkOperation* self;
	GearyFolder* folder;
	GeeCollection* ids;
	GCancellable* cancellable;
	GeeCollection* result;
	GearyFolderSupportMark* mark;
	GearyFolderSupportMark* _tmp0_;
	GeeCollection* _tmp1_;
	GeeCollection* _tmp2_;
	GearyEmailFlags* _tmp3_;
	GearyEmailFlags* _tmp4_;
	GeeCollection* _tmp5_;
	GError* _inner_error0_;
};

static gpointer geary_app_mark_operation_parent_class = NULL;

VALA_EXTERN GType geary_app_async_folder_operation_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GType geary_app_mark_operation_get_type (void) G_GNUC_CONST ;
VALA_EXTERN void geary_app_async_folder_operation_execute_async (GearyAppAsyncFolderOperation* self,
                                                     GearyFolder* folder,
                                                     GeeCollection* ids,
                                                     GCancellable* cancellable,
                                                     GAsyncReadyCallback _callback_,
                                                     gpointer _user_data_);
VALA_EXTERN GeeCollection* geary_app_async_folder_operation_execute_finish (GearyAppAsyncFolderOperation* self,
                                                                GAsyncResult* _res_,
                                                                GError** error);
VALA_EXTERN GType geary_app_async_folder_operation_get_folder_type (GearyAppAsyncFolderOperation* self);
VALA_EXTERN GearyAppMarkOperation* geary_app_mark_operation_new (GearyEmailFlags* flags_to_add,
                                                     GearyEmailFlags* flags_to_remove);
VALA_EXTERN GearyAppMarkOperation* geary_app_mark_operation_construct (GType object_type,
                                                           GearyEmailFlags* flags_to_add,
                                                           GearyEmailFlags* flags_to_remove);
VALA_EXTERN GearyAppAsyncFolderOperation* geary_app_async_folder_operation_construct (GType object_type);
static void geary_app_mark_operation_real_execute_async_data_free (gpointer _data);
static void geary_app_mark_operation_real_execute_async (GearyAppAsyncFolderOperation* base,
                                                  GearyFolder* folder,
                                                  GeeCollection* ids,
                                                  GCancellable* cancellable,
                                                  GAsyncReadyCallback _callback_,
                                                  gpointer _user_data_);
static gboolean geary_app_mark_operation_real_execute_async_co (GearyAppMarkOperationExecuteAsyncData* _data_);
static void geary_app_mark_operation_execute_async_ready (GObject* source_object,
                                                   GAsyncResult* _res_,
                                                   gpointer _user_data_);
static void geary_app_mark_operation_finalize (GObject * obj);
static GType geary_app_mark_operation_get_type_once (void);
static void _vala_geary_app_mark_operation_get_property (GObject * object,
                                                  guint property_id,
                                                  GValue * value,
                                                  GParamSpec * pspec);

static GType
geary_app_mark_operation_real_get_folder_type (GearyAppAsyncFolderOperation* base)
{
	GType result;
	GearyAppMarkOperation* self;
	self = G_TYPE_CHECK_INSTANCE_CAST (base, GEARY_APP_TYPE_MARK_OPERATION, GearyAppMarkOperation);
	result = GEARY_FOLDER_SUPPORT_TYPE_MARK;
	return result;
}

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

GearyAppMarkOperation*
geary_app_mark_operation_construct (GType object_type,
                                    GearyEmailFlags* flags_to_add,
                                    GearyEmailFlags* flags_to_remove)
{
	GearyAppMarkOperation * self = NULL;
	GearyEmailFlags* _tmp0_;
	GearyEmailFlags* _tmp1_;
	g_return_val_if_fail ((flags_to_add == NULL) || GEARY_IS_EMAIL_FLAGS (flags_to_add), NULL);
	g_return_val_if_fail ((flags_to_remove == NULL) || GEARY_IS_EMAIL_FLAGS (flags_to_remove), NULL);
	self = (GearyAppMarkOperation*) geary_app_async_folder_operation_construct (object_type);
	_tmp0_ = _g_object_ref0 (flags_to_add);
	_g_object_unref0 (self->flags_to_add);
	self->flags_to_add = _tmp0_;
	_tmp1_ = _g_object_ref0 (flags_to_remove);
	_g_object_unref0 (self->flags_to_remove);
	self->flags_to_remove = _tmp1_;
	return self;
}

GearyAppMarkOperation*
geary_app_mark_operation_new (GearyEmailFlags* flags_to_add,
                              GearyEmailFlags* flags_to_remove)
{
	return geary_app_mark_operation_construct (GEARY_APP_TYPE_MARK_OPERATION, flags_to_add, flags_to_remove);
}

static void
geary_app_mark_operation_real_execute_async_data_free (gpointer _data)
{
	GearyAppMarkOperationExecuteAsyncData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->folder);
	_g_object_unref0 (_data_->ids);
	_g_object_unref0 (_data_->cancellable);
	_g_object_unref0 (_data_->result);
	_g_object_unref0 (_data_->self);
	g_slice_free (GearyAppMarkOperationExecuteAsyncData, _data_);
}

static void
geary_app_mark_operation_real_execute_async (GearyAppAsyncFolderOperation* base,
                                             GearyFolder* folder,
                                             GeeCollection* ids,
                                             GCancellable* cancellable,
                                             GAsyncReadyCallback _callback_,
                                             gpointer _user_data_)
{
	GearyAppMarkOperation * self;
	GearyAppMarkOperationExecuteAsyncData* _data_;
	GearyAppMarkOperation* _tmp0_;
	GearyFolder* _tmp1_;
	GeeCollection* _tmp2_;
	GCancellable* _tmp3_;
	g_return_if_fail (GEARY_IS_FOLDER (folder));
	g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (ids, GEE_TYPE_COLLECTION));
	g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ()));
	self = G_TYPE_CHECK_INSTANCE_CAST (base, GEARY_APP_TYPE_MARK_OPERATION, GearyAppMarkOperation);
	_data_ = g_slice_new0 (GearyAppMarkOperationExecuteAsyncData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_app_mark_operation_real_execute_async_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (folder);
	_g_object_unref0 (_data_->folder);
	_data_->folder = _tmp1_;
	_tmp2_ = _g_object_ref0 (ids);
	_g_object_unref0 (_data_->ids);
	_data_->ids = _tmp2_;
	_tmp3_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp3_;
	geary_app_mark_operation_real_execute_async_co (_data_);
}

static GeeCollection*
geary_app_mark_operation_execute_finish (GearyAppAsyncFolderOperation* base,
                                         GAsyncResult* _res_,
                                         GError** error)
{
	GeeCollection* result;
	GearyAppMarkOperationExecuteAsyncData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return NULL;
	}
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

static void
geary_app_mark_operation_execute_async_ready (GObject* source_object,
                                              GAsyncResult* _res_,
                                              gpointer _user_data_)
{
	GearyAppMarkOperationExecuteAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_app_mark_operation_real_execute_async_co (_data_);
}

static gboolean
geary_app_mark_operation_real_execute_async_co (GearyAppMarkOperationExecuteAsyncData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = _g_object_ref0 (GEARY_FOLDER_SUPPORT_IS_MARK (_data_->folder) ? ((GearyFolderSupportMark*) _data_->folder) : NULL);
	_data_->mark = _data_->_tmp0_;
	_vala_assert (_data_->mark != NULL, "mark != null");
	_data_->_tmp1_ = geary_collection_copy (GEARY_TYPE_EMAIL_IDENTIFIER, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _data_->ids);
	_data_->_tmp2_ = _data_->_tmp1_;
	_data_->_tmp3_ = _data_->self->flags_to_add;
	_data_->_tmp4_ = _data_->self->flags_to_remove;
	_data_->_state_ = 1;
	geary_folder_support_mark_mark_email_async (_data_->mark, _data_->_tmp2_, _data_->_tmp3_, _data_->_tmp4_, _data_->cancellable, geary_app_mark_operation_execute_async_ready, _data_);
	return FALSE;
	_state_1:
	geary_folder_support_mark_mark_email_finish (_data_->mark, _data_->_res_, &_data_->_inner_error0_);
	_g_object_unref0 (_data_->_tmp2_);
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		_g_object_unref0 (_data_->mark);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp5_ = _g_object_ref0 (_data_->ids);
	_data_->result = _data_->_tmp5_;
	_g_object_unref0 (_data_->mark);
	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_mark_operation_class_init (GearyAppMarkOperationClass * klass,
                                     gpointer klass_data)
{
	geary_app_mark_operation_parent_class = g_type_class_peek_parent (klass);
	((GearyAppAsyncFolderOperationClass *) klass)->execute_async = (void (*) (GearyAppAsyncFolderOperation*, GearyFolder*, GeeCollection*, GCancellable*, GAsyncReadyCallback, gpointer)) geary_app_mark_operation_real_execute_async;
	((GearyAppAsyncFolderOperationClass *) klass)->execute_finish = (GeeCollection* (*) (GearyAppAsyncFolderOperation*, GAsyncResult*, GError**)) geary_app_mark_operation_execute_finish;
	GEARY_APP_ASYNC_FOLDER_OPERATION_CLASS (klass)->get_folder_type = geary_app_mark_operation_real_get_folder_type;
	G_OBJECT_CLASS (klass)->get_property = _vala_geary_app_mark_operation_get_property;
	G_OBJECT_CLASS (klass)->finalize = geary_app_mark_operation_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), GEARY_APP_MARK_OPERATION_FOLDER_TYPE_PROPERTY, geary_app_mark_operation_properties[GEARY_APP_MARK_OPERATION_FOLDER_TYPE_PROPERTY] = g_param_spec_gtype ("folder-type", "folder-type", "folder-type", G_TYPE_NONE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
}

static void
geary_app_mark_operation_instance_init (GearyAppMarkOperation * self,
                                        gpointer klass)
{
}

static void
geary_app_mark_operation_finalize (GObject * obj)
{
	GearyAppMarkOperation * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GEARY_APP_TYPE_MARK_OPERATION, GearyAppMarkOperation);
	_g_object_unref0 (self->flags_to_add);
	_g_object_unref0 (self->flags_to_remove);
	G_OBJECT_CLASS (geary_app_mark_operation_parent_class)->finalize (obj);
}

 G_GNUC_NO_INLINE static GType
geary_app_mark_operation_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GearyAppMarkOperationClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) geary_app_mark_operation_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GearyAppMarkOperation), 0, (GInstanceInitFunc) geary_app_mark_operation_instance_init, NULL };
	GType geary_app_mark_operation_type_id;
	geary_app_mark_operation_type_id = g_type_register_static (GEARY_APP_TYPE_ASYNC_FOLDER_OPERATION, "GearyAppMarkOperation", &g_define_type_info, 0);
	return geary_app_mark_operation_type_id;
}

GType
geary_app_mark_operation_get_type (void)
{
	static gsize geary_app_mark_operation_type_id__once = 0;
	if (g_once_init_enter (&geary_app_mark_operation_type_id__once)) {
		GType geary_app_mark_operation_type_id;
		geary_app_mark_operation_type_id = geary_app_mark_operation_get_type_once ();
		g_once_init_leave (&geary_app_mark_operation_type_id__once, geary_app_mark_operation_type_id);
	}
	return geary_app_mark_operation_type_id__once;
}

static void
_vala_geary_app_mark_operation_get_property (GObject * object,
                                             guint property_id,
                                             GValue * value,
                                             GParamSpec * pspec)
{
	GearyAppMarkOperation * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GEARY_APP_TYPE_MARK_OPERATION, GearyAppMarkOperation);
	switch (property_id) {
		case GEARY_APP_MARK_OPERATION_FOLDER_TYPE_PROPERTY:
		g_value_set_gtype (value, geary_app_async_folder_operation_get_folder_type (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_APP_TYPE_ASYNC_FOLDER_OPERATION, GearyAppAsyncFolderOperation)));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

