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

#define GEARY_APP_TYPE_LOCAL_SEARCH_OPERATION (geary_app_local_search_operation_get_type ())
#define GEARY_APP_LOCAL_SEARCH_OPERATION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEARY_APP_TYPE_LOCAL_SEARCH_OPERATION, GearyAppLocalSearchOperation))
#define GEARY_APP_LOCAL_SEARCH_OPERATION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GEARY_APP_TYPE_LOCAL_SEARCH_OPERATION, GearyAppLocalSearchOperationClass))
#define GEARY_APP_IS_LOCAL_SEARCH_OPERATION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEARY_APP_TYPE_LOCAL_SEARCH_OPERATION))
#define GEARY_APP_IS_LOCAL_SEARCH_OPERATION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEARY_APP_TYPE_LOCAL_SEARCH_OPERATION))
#define GEARY_APP_LOCAL_SEARCH_OPERATION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GEARY_APP_TYPE_LOCAL_SEARCH_OPERATION, GearyAppLocalSearchOperationClass))

typedef struct _GearyAppLocalSearchOperation GearyAppLocalSearchOperation;
typedef struct _GearyAppLocalSearchOperationClass GearyAppLocalSearchOperationClass;
typedef struct _GearyAppLocalSearchOperationPrivate GearyAppLocalSearchOperationPrivate;
enum  {
	GEARY_APP_LOCAL_SEARCH_OPERATION_0_PROPERTY,
	GEARY_APP_LOCAL_SEARCH_OPERATION_NUM_PROPERTIES
};
static GParamSpec* geary_app_local_search_operation_properties[GEARY_APP_LOCAL_SEARCH_OPERATION_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef struct _GearyAppLocalSearchOperationExecuteAsyncData GearyAppLocalSearchOperationExecuteAsyncData;

struct _GearyAppLocalSearchOperation {
	GearyNonblockingBatchOperation parent_instance;
	GearyAccount* account;
	GearyRFC822MessageID* message_id;
	GearyEmailField required_fields;
	GeeCollection* blacklist;
	GearyEmailFlags* flag_blacklist;
	GeeMultiMap* emails;
	GearyAppLocalSearchOperationPrivate * priv;
};

struct _GearyAppLocalSearchOperationClass {
	GearyNonblockingBatchOperationClass parent_class;
};

struct _GearyAppLocalSearchOperationExecuteAsyncData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	GearyAppLocalSearchOperation* self;
	GCancellable* cancellable;
	GObject* result;
	GeeMultiMap* _tmp0_;
	GearyAccount* _tmp1_;
	GearyRFC822MessageID* _tmp2_;
	GeeCollection* _tmp3_;
	GearyEmailFlags* _tmp4_;
	GeeMultiMap* _tmp5_;
	GeeMultiMap* _tmp6_;
	GError* _inner_error0_;
};

static gpointer geary_app_local_search_operation_parent_class = NULL;

VALA_EXTERN GType geary_app_local_search_operation_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GearyAppLocalSearchOperation* geary_app_local_search_operation_new (GearyAccount* account,
                                                                    GearyRFC822MessageID* message_id,
                                                                    GearyEmailField required_fields,
                                                                    GeeCollection* blacklist,
                                                                    GearyEmailFlags* flag_blacklist);
VALA_EXTERN GearyAppLocalSearchOperation* geary_app_local_search_operation_construct (GType object_type,
                                                                          GearyAccount* account,
                                                                          GearyRFC822MessageID* message_id,
                                                                          GearyEmailField required_fields,
                                                                          GeeCollection* blacklist,
                                                                          GearyEmailFlags* flag_blacklist);
static void geary_app_local_search_operation_real_execute_async_data_free (gpointer _data);
static void geary_app_local_search_operation_real_execute_async (GearyNonblockingBatchOperation* base,
                                                          GCancellable* cancellable,
                                                          GAsyncReadyCallback _callback_,
                                                          gpointer _user_data_);
static gboolean geary_app_local_search_operation_real_execute_async_co (GearyAppLocalSearchOperationExecuteAsyncData* _data_);
static void geary_app_local_search_operation_execute_async_ready (GObject* source_object,
                                                           GAsyncResult* _res_,
                                                           gpointer _user_data_);
static void geary_app_local_search_operation_finalize (GObject * obj);
static GType geary_app_local_search_operation_get_type_once (void);

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

GearyAppLocalSearchOperation*
geary_app_local_search_operation_construct (GType object_type,
                                            GearyAccount* account,
                                            GearyRFC822MessageID* message_id,
                                            GearyEmailField required_fields,
                                            GeeCollection* blacklist,
                                            GearyEmailFlags* flag_blacklist)
{
	GearyAppLocalSearchOperation * self = NULL;
	GearyAccount* _tmp0_;
	GearyRFC822MessageID* _tmp1_;
	GeeCollection* _tmp2_;
	GearyEmailFlags* _tmp3_;
	g_return_val_if_fail (GEARY_IS_ACCOUNT (account), NULL);
	g_return_val_if_fail (GEARY_RF_C822_IS_MESSAGE_ID (message_id), NULL);
	g_return_val_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (blacklist, GEE_TYPE_COLLECTION), NULL);
	g_return_val_if_fail ((flag_blacklist == NULL) || GEARY_IS_EMAIL_FLAGS (flag_blacklist), NULL);
	self = (GearyAppLocalSearchOperation*) geary_nonblocking_batch_operation_construct (object_type);
	_tmp0_ = _g_object_ref0 (account);
	_g_object_unref0 (self->account);
	self->account = _tmp0_;
	_tmp1_ = _g_object_ref0 (message_id);
	_g_object_unref0 (self->message_id);
	self->message_id = _tmp1_;
	self->required_fields = required_fields;
	_tmp2_ = _g_object_ref0 (blacklist);
	_g_object_unref0 (self->blacklist);
	self->blacklist = _tmp2_;
	_tmp3_ = _g_object_ref0 (flag_blacklist);
	_g_object_unref0 (self->flag_blacklist);
	self->flag_blacklist = _tmp3_;
	return self;
}

GearyAppLocalSearchOperation*
geary_app_local_search_operation_new (GearyAccount* account,
                                      GearyRFC822MessageID* message_id,
                                      GearyEmailField required_fields,
                                      GeeCollection* blacklist,
                                      GearyEmailFlags* flag_blacklist)
{
	return geary_app_local_search_operation_construct (GEARY_APP_TYPE_LOCAL_SEARCH_OPERATION, account, message_id, required_fields, blacklist, flag_blacklist);
}

static void
geary_app_local_search_operation_real_execute_async_data_free (gpointer _data)
{
	GearyAppLocalSearchOperationExecuteAsyncData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->cancellable);
	_g_object_unref0 (_data_->result);
	_g_object_unref0 (_data_->self);
	g_slice_free (GearyAppLocalSearchOperationExecuteAsyncData, _data_);
}

static void
geary_app_local_search_operation_real_execute_async (GearyNonblockingBatchOperation* base,
                                                     GCancellable* cancellable,
                                                     GAsyncReadyCallback _callback_,
                                                     gpointer _user_data_)
{
	GearyAppLocalSearchOperation * self;
	GearyAppLocalSearchOperationExecuteAsyncData* _data_;
	GearyAppLocalSearchOperation* _tmp0_;
	GCancellable* _tmp1_;
	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_LOCAL_SEARCH_OPERATION, GearyAppLocalSearchOperation);
	_data_ = g_slice_new0 (GearyAppLocalSearchOperationExecuteAsyncData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, geary_app_local_search_operation_real_execute_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_local_search_operation_real_execute_async_co (_data_);
}

static GObject*
geary_app_local_search_operation_execute_finish (GearyNonblockingBatchOperation* base,
                                                 GAsyncResult* _res_,
                                                 GError** error)
{
	GObject* result;
	GearyAppLocalSearchOperationExecuteAsyncData* _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_local_search_operation_execute_async_ready (GObject* source_object,
                                                      GAsyncResult* _res_,
                                                      gpointer _user_data_)
{
	GearyAppLocalSearchOperationExecuteAsyncData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	geary_app_local_search_operation_real_execute_async_co (_data_);
}

static gboolean
geary_app_local_search_operation_real_execute_async_co (GearyAppLocalSearchOperationExecuteAsyncData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp1_ = _data_->self->account;
	_data_->_tmp2_ = _data_->self->message_id;
	_data_->_tmp3_ = _data_->self->blacklist;
	_data_->_tmp4_ = _data_->self->flag_blacklist;
	_data_->_state_ = 1;
	geary_account_local_search_message_id_async (_data_->_tmp1_, _data_->_tmp2_, _data_->self->required_fields, FALSE, _data_->_tmp3_, _data_->_tmp4_, NULL, geary_app_local_search_operation_execute_async_ready, _data_);
	return FALSE;
	_state_1:
	_data_->_tmp5_ = geary_account_local_search_message_id_finish (_data_->_tmp1_, _data_->_res_, &_data_->_inner_error0_);
	_data_->_tmp0_ = _data_->_tmp5_;
	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;
	}
	_data_->_tmp6_ = _data_->_tmp0_;
	_data_->_tmp0_ = NULL;
	_g_object_unref0 (_data_->self->emails);
	_data_->self->emails = _data_->_tmp6_;
	_data_->result = NULL;
	_g_object_unref0 (_data_->_tmp0_);
	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_local_search_operation_class_init (GearyAppLocalSearchOperationClass * klass,
                                             gpointer klass_data)
{
	geary_app_local_search_operation_parent_class = g_type_class_peek_parent (klass);
	((GearyNonblockingBatchOperationClass *) klass)->execute_async = (void (*) (GearyNonblockingBatchOperation*, GCancellable*, GAsyncReadyCallback, gpointer)) geary_app_local_search_operation_real_execute_async;
	((GearyNonblockingBatchOperationClass *) klass)->execute_finish = (GObject* (*) (GearyNonblockingBatchOperation*, GAsyncResult*, GError**)) geary_app_local_search_operation_execute_finish;
	G_OBJECT_CLASS (klass)->finalize = geary_app_local_search_operation_finalize;
}

static void
geary_app_local_search_operation_instance_init (GearyAppLocalSearchOperation * self,
                                                gpointer klass)
{
	self->emails = NULL;
}

static void
geary_app_local_search_operation_finalize (GObject * obj)
{
	GearyAppLocalSearchOperation * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GEARY_APP_TYPE_LOCAL_SEARCH_OPERATION, GearyAppLocalSearchOperation);
	_g_object_unref0 (self->account);
	_g_object_unref0 (self->message_id);
	_g_object_unref0 (self->blacklist);
	_g_object_unref0 (self->flag_blacklist);
	_g_object_unref0 (self->emails);
	G_OBJECT_CLASS (geary_app_local_search_operation_parent_class)->finalize (obj);
}

 G_GNUC_NO_INLINE static GType
geary_app_local_search_operation_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GearyAppLocalSearchOperationClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) geary_app_local_search_operation_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GearyAppLocalSearchOperation), 0, (GInstanceInitFunc) geary_app_local_search_operation_instance_init, NULL };
	GType geary_app_local_search_operation_type_id;
	geary_app_local_search_operation_type_id = g_type_register_static (GEARY_NONBLOCKING_TYPE_BATCH_OPERATION, "GearyAppLocalSearchOperation", &g_define_type_info, 0);
	return geary_app_local_search_operation_type_id;
}

GType
geary_app_local_search_operation_get_type (void)
{
	static gsize geary_app_local_search_operation_type_id__once = 0;
	if (g_once_init_enter (&geary_app_local_search_operation_type_id__once)) {
		GType geary_app_local_search_operation_type_id;
		geary_app_local_search_operation_type_id = geary_app_local_search_operation_get_type_once ();
		g_once_init_leave (&geary_app_local_search_operation_type_id__once, geary_app_local_search_operation_type_id);
	}
	return geary_app_local_search_operation_type_id__once;
}

