/* ToolJoblet.c generated by valac 0.56.18-dirty, the Vala compiler
 * generated from ToolJoblet.vala, do not modify */

/* -*- Mode: Vala; indent-tabs-mode: nil; tab-width: 2 -*-
 *
 * SPDX-License-Identifier: GPL-3.0-or-later
 * SPDX-FileCopyrightText: Michael Terry
 */

#include "deja.h"
#include <glib-object.h>
#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include <gio/gio.h>
#include <glib/gi18n-lib.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 DEJA_DUP_TYPE_TOOL_JOBLET (deja_dup_tool_joblet_get_type ())
#define DEJA_DUP_TOOL_JOBLET(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DEJA_DUP_TYPE_TOOL_JOBLET, DejaDupToolJoblet))
#define DEJA_DUP_TOOL_JOBLET_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DEJA_DUP_TYPE_TOOL_JOBLET, DejaDupToolJobletClass))
#define DEJA_DUP_IS_TOOL_JOBLET(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DEJA_DUP_TYPE_TOOL_JOBLET))
#define DEJA_DUP_IS_TOOL_JOBLET_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DEJA_DUP_TYPE_TOOL_JOBLET))
#define DEJA_DUP_TOOL_JOBLET_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DEJA_DUP_TYPE_TOOL_JOBLET, DejaDupToolJobletClass))

typedef struct _DejaDupToolJoblet DejaDupToolJoblet;
typedef struct _DejaDupToolJobletClass DejaDupToolJobletClass;
typedef struct _DejaDupToolJobletPrivate DejaDupToolJobletPrivate;

#define TYPE_TOOL_INSTANCE (tool_instance_get_type ())
#define TOOL_INSTANCE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TOOL_INSTANCE, ToolInstance))
#define TOOL_INSTANCE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_TOOL_INSTANCE, ToolInstanceClass))
#define IS_TOOL_INSTANCE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_TOOL_INSTANCE))
#define IS_TOOL_INSTANCE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_TOOL_INSTANCE))
#define TOOL_INSTANCE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_TOOL_INSTANCE, ToolInstanceClass))

typedef struct _ToolInstance ToolInstance;
typedef struct _ToolInstanceClass ToolInstanceClass;

#define DEJA_DUP_TYPE_TOOL_JOB_CHAIN (deja_dup_tool_job_chain_get_type ())
#define DEJA_DUP_TOOL_JOB_CHAIN(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DEJA_DUP_TYPE_TOOL_JOB_CHAIN, DejaDupToolJobChain))
#define DEJA_DUP_TOOL_JOB_CHAIN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DEJA_DUP_TYPE_TOOL_JOB_CHAIN, DejaDupToolJobChainClass))
#define DEJA_DUP_IS_TOOL_JOB_CHAIN(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DEJA_DUP_TYPE_TOOL_JOB_CHAIN))
#define DEJA_DUP_IS_TOOL_JOB_CHAIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DEJA_DUP_TYPE_TOOL_JOB_CHAIN))
#define DEJA_DUP_TOOL_JOB_CHAIN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DEJA_DUP_TYPE_TOOL_JOB_CHAIN, DejaDupToolJobChainClass))

typedef struct _DejaDupToolJobChain DejaDupToolJobChain;
typedef struct _DejaDupToolJobChainClass DejaDupToolJobChainClass;
enum  {
	DEJA_DUP_TOOL_JOBLET_0_PROPERTY,
	DEJA_DUP_TOOL_JOBLET_CHAIN_PROPERTY,
	DEJA_DUP_TOOL_JOBLET_NUM_PROPERTIES
};
static GParamSpec* deja_dup_tool_joblet_properties[DEJA_DUP_TOOL_JOBLET_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
typedef struct _DejaDupToolJobletStartData DejaDupToolJobletStartData;
typedef struct _DejaDupToolJobletPrepareData DejaDupToolJobletPrepareData;
typedef struct _DejaDupToolJobletStartInstData DejaDupToolJobletStartInstData;
#define _g_free0(var) (var = (g_free (var), NULL))

struct _DejaDupToolJoblet {
	DejaDupToolJob parent_instance;
	DejaDupToolJobletPrivate * priv;
};

struct _DejaDupToolJobletClass {
	DejaDupToolJobClass parent_class;
	ToolInstance* (*make_instance) (DejaDupToolJoblet* self);
	void (*prepare_args) (DejaDupToolJoblet* self, GList** argv, GList** envp, GError** error);
	void (*prepare) (DejaDupToolJoblet* self, GAsyncReadyCallback _callback_, gpointer _user_data_);
	void (*prepare_finish) (DejaDupToolJoblet* self, GAsyncResult* _res_, GError** error);
	void (*handle_done) (DejaDupToolJoblet* self, gboolean success, gboolean cancelled);
};

struct _DejaDupToolJobletPrivate {
	DejaDupToolJobChain* _chain;
	ToolInstance* inst;
	GList* handlers;
	gboolean error_issued;
};

struct _DejaDupToolJobletStartData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	DejaDupToolJoblet* self;
	GList* argv;
	GList* envp;
	GError* e;
	GError* _tmp0_;
	const gchar* _tmp1_;
	GList* _tmp2_;
	GList* _tmp3_;
	GError* _inner_error0_;
};

struct _DejaDupToolJobletPrepareData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	DejaDupToolJoblet* self;
};

struct _DejaDupToolJobletStartInstData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	DejaDupToolJoblet* self;
	GList* argv;
	GList* envp;
	ToolInstance* _tmp0_;
	ToolInstance* _tmp1_;
	gulong _tmp2_;
	ToolInstance* _tmp3_;
};

static gint DejaDupToolJoblet_private_offset;
static gpointer deja_dup_tool_joblet_parent_class = NULL;

VALA_EXTERN GType deja_dup_tool_joblet_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GType tool_instance_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GType deja_dup_tool_job_chain_get_type (void) G_GNUC_CONST ;
VALA_EXTERN ToolInstance* deja_dup_tool_joblet_make_instance (DejaDupToolJoblet* self);
VALA_EXTERN void deja_dup_tool_joblet_prepare_args (DejaDupToolJoblet* self,
                                        GList** argv,
                                        GList** envp,
                                        GError** error);
VALA_EXTERN void deja_dup_tool_joblet_prepare (DejaDupToolJoblet* self,
                                   GAsyncReadyCallback _callback_,
                                   gpointer _user_data_);
VALA_EXTERN void deja_dup_tool_joblet_prepare_finish (DejaDupToolJoblet* self,
                                          GAsyncResult* _res_,
                                          GError** error);
VALA_EXTERN void deja_dup_tool_joblet_handle_done (DejaDupToolJoblet* self,
                                       gboolean success,
                                       gboolean cancelled);
static void deja_dup_tool_joblet_real_stop (DejaDupToolJob* base);
VALA_EXTERN void deja_dup_tool_joblet_disconnect_inst (DejaDupToolJoblet* self);
static void deja_dup_tool_joblet_real_pause (DejaDupToolJob* base,
                                      const gchar* reason);
VALA_EXTERN void tool_instance_pause (ToolInstance* self);
static void deja_dup_tool_joblet_real_resume (DejaDupToolJob* base);
VALA_EXTERN void tool_instance_resume (ToolInstance* self);
static void deja_dup_tool_joblet_real_start_data_free (gpointer _data);
static void deja_dup_tool_joblet_real_start (DejaDupToolJob* base,
                                      GAsyncReadyCallback _callback_,
                                      gpointer _user_data_);
static gboolean deja_dup_tool_joblet_real_start_co (DejaDupToolJobletStartData* _data_);
static void deja_dup_tool_joblet_start_ready (GObject* source_object,
                                       GAsyncResult* _res_,
                                       gpointer _user_data_);
VALA_EXTERN void deja_dup_tool_joblet_show_error (DejaDupToolJoblet* self,
                                      const gchar* msg,
                                      const gchar* detail);
static void _g_free0_ (gpointer var);
static inline void _g_list_free__g_free0_ (GList* self);
static void deja_dup_tool_joblet_start_inst (DejaDupToolJoblet* self,
                                      GList* argv,
                                      GList* envp,
                                      GAsyncReadyCallback _callback_,
                                      gpointer _user_data_);
static void deja_dup_tool_joblet_start_inst_finish (DejaDupToolJoblet* self,
                                             GAsyncResult* _res_);
static ToolInstance* deja_dup_tool_joblet_real_make_instance (DejaDupToolJoblet* self);
static void deja_dup_tool_joblet_real_prepare_args (DejaDupToolJoblet* self,
                                             GList** argv,
                                             GList** envp,
                                             GError** error);
static void deja_dup_tool_joblet_real_prepare_data_free (gpointer _data);
static void deja_dup_tool_joblet_real_prepare (DejaDupToolJoblet* self,
                                        GAsyncReadyCallback _callback_,
                                        gpointer _user_data_);
static gboolean deja_dup_tool_joblet_real_prepare_co (DejaDupToolJobletPrepareData* _data_);
VALA_EXTERN void deja_dup_tool_joblet_add_handler (DejaDupToolJoblet* self,
                                       gulong id);
VALA_EXTERN void deja_dup_tool_joblet_finish (DejaDupToolJoblet* self);
VALA_EXTERN void tool_instance_cancel (ToolInstance* self);
static void deja_dup_tool_joblet_start_inst_data_free (gpointer _data);
static gboolean deja_dup_tool_joblet_start_inst_co (DejaDupToolJobletStartInstData* _data_);
static void _deja_dup_tool_joblet_handle_done_tool_instance_done (ToolInstance* _sender,
                                                           gboolean success,
                                                           gboolean cancelled,
                                                           gpointer self);
VALA_EXTERN void tool_instance_start (ToolInstance* self,
                          GList* argv_in,
                          GList* envp_in,
                          GAsyncReadyCallback _callback_,
                          gpointer _user_data_);
VALA_EXTERN void tool_instance_start_finish (ToolInstance* self,
                                 GAsyncResult* _res_);
static void deja_dup_tool_joblet_start_inst_ready (GObject* source_object,
                                            GAsyncResult* _res_,
                                            gpointer _user_data_);
static void deja_dup_tool_joblet_real_handle_done (DejaDupToolJoblet* self,
                                            gboolean success,
                                            gboolean cancelled);
VALA_EXTERN gchar* deja_dup_tool_joblet_make_verification_error_message (const gchar* msg);
VALA_EXTERN DejaDupToolJoblet* deja_dup_tool_joblet_construct (GType object_type);
VALA_EXTERN DejaDupToolJobChain* deja_dup_tool_joblet_get_chain (DejaDupToolJoblet* self);
VALA_EXTERN void deja_dup_tool_joblet_set_chain (DejaDupToolJoblet* self,
                                     DejaDupToolJobChain* value);
static void deja_dup_tool_joblet_finalize (GObject * obj);
static GType deja_dup_tool_joblet_get_type_once (void);
static void _vala_deja_dup_tool_joblet_get_property (GObject * object,
                                              guint property_id,
                                              GValue * value,
                                              GParamSpec * pspec);
static void _vala_deja_dup_tool_joblet_set_property (GObject * object,
                                              guint property_id,
                                              const GValue * value,
                                              GParamSpec * pspec);

static inline gpointer
deja_dup_tool_joblet_get_instance_private (DejaDupToolJoblet* self)
{
	return G_STRUCT_MEMBER_P (self, DejaDupToolJoblet_private_offset);
}

static void
deja_dup_tool_joblet_real_stop (DejaDupToolJob* base)
{
	DejaDupToolJoblet * self;
	self = (DejaDupToolJoblet*) base;
	deja_dup_tool_joblet_disconnect_inst (self);
	g_signal_emit_by_name ((DejaDupToolJob*) self, "done", TRUE, TRUE);
}

static void
deja_dup_tool_joblet_real_pause (DejaDupToolJob* base,
                                 const gchar* reason)
{
	DejaDupToolJoblet * self;
	ToolInstance* _tmp0_;
	self = (DejaDupToolJoblet*) base;
	_tmp0_ = self->priv->inst;
	if (_tmp0_ != NULL) {
		ToolInstance* _tmp1_;
		_tmp1_ = self->priv->inst;
		tool_instance_pause (_tmp1_);
	}
}

static void
deja_dup_tool_joblet_real_resume (DejaDupToolJob* base)
{
	DejaDupToolJoblet * self;
	ToolInstance* _tmp0_;
	self = (DejaDupToolJoblet*) base;
	_tmp0_ = self->priv->inst;
	if (_tmp0_ != NULL) {
		ToolInstance* _tmp1_;
		_tmp1_ = self->priv->inst;
		tool_instance_resume (_tmp1_);
	}
}

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

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

static void
deja_dup_tool_joblet_real_start (DejaDupToolJob* base,
                                 GAsyncReadyCallback _callback_,
                                 gpointer _user_data_)
{
	DejaDupToolJoblet * self;
	DejaDupToolJobletStartData* _data_;
	DejaDupToolJoblet* _tmp0_;
	self = (DejaDupToolJoblet*) base;
	_data_ = g_slice_new0 (DejaDupToolJobletStartData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, deja_dup_tool_joblet_real_start_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	deja_dup_tool_joblet_real_start_co (_data_);
}

static void
deja_dup_tool_joblet_start_finish (DejaDupToolJob* base,
                                   GAsyncResult* _res_)
{
	DejaDupToolJobletStartData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
}

static void
deja_dup_tool_joblet_start_ready (GObject* source_object,
                                  GAsyncResult* _res_,
                                  gpointer _user_data_)
{
	DejaDupToolJobletStartData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	deja_dup_tool_joblet_real_start_co (_data_);
}

static void
_g_free0_ (gpointer var)
{
	var = (g_free (var), NULL);
}

static inline void
_g_list_free__g_free0_ (GList* self)
{
	g_list_free_full (self, (GDestroyNotify) _g_free0_);
}

static gboolean
deja_dup_tool_joblet_real_start_co (DejaDupToolJobletStartData* _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:
	_data_->argv = NULL;
	_data_->envp = NULL;
	{
		_data_->_state_ = 1;
		deja_dup_tool_joblet_prepare (_data_->self, deja_dup_tool_joblet_start_ready, _data_);
		return FALSE;
		_state_1:
		deja_dup_tool_joblet_prepare_finish (_data_->self, _data_->_res_, &_data_->_inner_error0_);
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		deja_dup_tool_joblet_prepare_args (_data_->self, &_data_->argv, &_data_->envp, &_data_->_inner_error0_);
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
	}
	goto __finally0;
	__catch0_g_error:
	{
		_data_->e = _data_->_inner_error0_;
		_data_->_inner_error0_ = NULL;
		_data_->_tmp0_ = _data_->e;
		_data_->_tmp1_ = _data_->_tmp0_->message;
		deja_dup_tool_joblet_show_error (_data_->self, _data_->_tmp1_, NULL);
		g_signal_emit_by_name ((DejaDupToolJob*) _data_->self, "done", FALSE, FALSE);
		_g_error_free0 (_data_->e);
		(_data_->envp == NULL) ? NULL : (_data_->envp = (_g_list_free__g_free0_ (_data_->envp), NULL));
		(_data_->argv == NULL) ? NULL : (_data_->argv = (_g_list_free__g_free0_ (_data_->argv), NULL));
		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;
	}
	__finally0:
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		(_data_->envp == NULL) ? NULL : (_data_->envp = (_g_list_free__g_free0_ (_data_->envp), NULL));
		(_data_->argv == NULL) ? NULL : (_data_->argv = (_g_list_free__g_free0_ (_data_->argv), NULL));
		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_->_tmp2_ = _data_->argv;
	_data_->_tmp3_ = _data_->envp;
	_data_->_state_ = 2;
	deja_dup_tool_joblet_start_inst (_data_->self, _data_->_tmp2_, _data_->_tmp3_, deja_dup_tool_joblet_start_ready, _data_);
	return FALSE;
	_state_2:
	deja_dup_tool_joblet_start_inst_finish (_data_->self, _data_->_res_);
	(_data_->envp == NULL) ? NULL : (_data_->envp = (_g_list_free__g_free0_ (_data_->envp), NULL));
	(_data_->argv == NULL) ? NULL : (_data_->argv = (_g_list_free__g_free0_ (_data_->argv), NULL));
	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 ToolInstance*
deja_dup_tool_joblet_real_make_instance (DejaDupToolJoblet* self)
{
	g_critical ("Type `%s' does not implement abstract method `deja_dup_tool_joblet_make_instance'", g_type_name (G_TYPE_FROM_INSTANCE (self)));
	return NULL;
}

ToolInstance*
deja_dup_tool_joblet_make_instance (DejaDupToolJoblet* self)
{
	DejaDupToolJobletClass* _klass_;
	g_return_val_if_fail (self != NULL, NULL);
	_klass_ = DEJA_DUP_TOOL_JOBLET_GET_CLASS (self);
	if (_klass_->make_instance) {
		return _klass_->make_instance (self);
	}
	return NULL;
}

static void
deja_dup_tool_joblet_real_prepare_args (DejaDupToolJoblet* self,
                                        GList** argv,
                                        GList** envp,
                                        GError** error)
{
	g_critical ("Type `%s' does not implement abstract method `deja_dup_tool_joblet_prepare_args'", g_type_name (G_TYPE_FROM_INSTANCE (self)));
	return;
}

void
deja_dup_tool_joblet_prepare_args (DejaDupToolJoblet* self,
                                   GList** argv,
                                   GList** envp,
                                   GError** error)
{
	DejaDupToolJobletClass* _klass_;
	g_return_if_fail (self != NULL);
	_klass_ = DEJA_DUP_TOOL_JOBLET_GET_CLASS (self);
	if (_klass_->prepare_args) {
		_klass_->prepare_args (self, argv, envp, error);
	}
}

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

static void
deja_dup_tool_joblet_real_prepare (DejaDupToolJoblet* self,
                                   GAsyncReadyCallback _callback_,
                                   gpointer _user_data_)
{
	DejaDupToolJobletPrepareData* _data_;
	DejaDupToolJoblet* _tmp0_;
	_data_ = g_slice_new0 (DejaDupToolJobletPrepareData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, deja_dup_tool_joblet_real_prepare_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	deja_dup_tool_joblet_real_prepare_co (_data_);
}

static void
deja_dup_tool_joblet_real_prepare_finish (DejaDupToolJoblet* self,
                                          GAsyncResult* _res_,
                                          GError** error)
{
	DejaDupToolJobletPrepareData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return;
	}
}

static gboolean
deja_dup_tool_joblet_real_prepare_co (DejaDupToolJobletPrepareData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	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;
}

void
deja_dup_tool_joblet_prepare (DejaDupToolJoblet* self,
                              GAsyncReadyCallback _callback_,
                              gpointer _user_data_)
{
	DejaDupToolJobletClass* _klass_;
	_klass_ = DEJA_DUP_TOOL_JOBLET_GET_CLASS (self);
	if (_klass_->prepare) {
		_klass_->prepare (self, _callback_, _user_data_);
	}
}

void
deja_dup_tool_joblet_prepare_finish (DejaDupToolJoblet* self,
                                     GAsyncResult* _res_,
                                     GError** error)
{
	DejaDupToolJobletClass* _klass_;
	_klass_ = DEJA_DUP_TOOL_JOBLET_GET_CLASS (self);
	if (_klass_->prepare_finish) {
		_klass_->prepare_finish (self, _res_, error);
	}
}

void
deja_dup_tool_joblet_add_handler (DejaDupToolJoblet* self,
                                  gulong id)
{
	g_return_if_fail (self != NULL);
	self->priv->handlers = g_list_append (self->priv->handlers, (gpointer) ((guintptr) id));
}

void
deja_dup_tool_joblet_show_error (DejaDupToolJoblet* self,
                                 const gchar* msg,
                                 const gchar* detail)
{
	g_return_if_fail (self != NULL);
	g_return_if_fail (msg != NULL);
	self->priv->error_issued = TRUE;
	g_signal_emit_by_name ((DejaDupToolJob*) self, "raise-error", msg, detail);
}

void
deja_dup_tool_joblet_finish (DejaDupToolJoblet* self)
{
	g_return_if_fail (self != NULL);
	deja_dup_tool_joblet_disconnect_inst (self);
	g_signal_emit_by_name ((DejaDupToolJob*) self, "done", TRUE, FALSE);
}

void
deja_dup_tool_joblet_disconnect_inst (DejaDupToolJoblet* self)
{
	ToolInstance* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->inst;
	if (_tmp0_ != NULL) {
		GList* _tmp1_;
		ToolInstance* _tmp3_;
		_tmp1_ = self->priv->handlers;
		{
			GList* id_collection = NULL;
			GList* id_it = NULL;
			id_collection = _tmp1_;
			for (id_it = id_collection; id_it != NULL; id_it = id_it->next) {
				gulong id = 0UL;
				id = (gulong) ((guintptr) id_it->data);
				{
					ToolInstance* _tmp2_;
					_tmp2_ = self->priv->inst;
					g_signal_handler_disconnect ((GObject*) _tmp2_, id);
				}
			}
		}
		(self->priv->handlers == NULL) ? NULL : (self->priv->handlers = (g_list_free (self->priv->handlers), NULL));
		self->priv->handlers = NULL;
		_tmp3_ = self->priv->inst;
		tool_instance_cancel (_tmp3_);
		_g_object_unref0 (self->priv->inst);
		self->priv->inst = NULL;
	}
}

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

static void
deja_dup_tool_joblet_start_inst (DejaDupToolJoblet* self,
                                 GList* argv,
                                 GList* envp,
                                 GAsyncReadyCallback _callback_,
                                 gpointer _user_data_)
{
	DejaDupToolJobletStartInstData* _data_;
	DejaDupToolJoblet* _tmp0_;
	g_return_if_fail (self != NULL);
	_data_ = g_slice_new0 (DejaDupToolJobletStartInstData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, deja_dup_tool_joblet_start_inst_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_data_->argv = argv;
	_data_->envp = envp;
	deja_dup_tool_joblet_start_inst_co (_data_);
}

static void
deja_dup_tool_joblet_start_inst_finish (DejaDupToolJoblet* self,
                                        GAsyncResult* _res_)
{
	DejaDupToolJobletStartInstData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
}

static void
_deja_dup_tool_joblet_handle_done_tool_instance_done (ToolInstance* _sender,
                                                      gboolean success,
                                                      gboolean cancelled,
                                                      gpointer self)
{
	deja_dup_tool_joblet_handle_done ((DejaDupToolJoblet*) self, success, cancelled);
}

static void
deja_dup_tool_joblet_start_inst_ready (GObject* source_object,
                                       GAsyncResult* _res_,
                                       gpointer _user_data_)
{
	DejaDupToolJobletStartInstData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	deja_dup_tool_joblet_start_inst_co (_data_);
}

static gboolean
deja_dup_tool_joblet_start_inst_co (DejaDupToolJobletStartInstData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	deja_dup_tool_joblet_disconnect_inst (_data_->self);
	_data_->_tmp0_ = deja_dup_tool_joblet_make_instance (_data_->self);
	_g_object_unref0 (_data_->self->priv->inst);
	_data_->self->priv->inst = _data_->_tmp0_;
	_data_->_tmp1_ = _data_->self->priv->inst;
	_data_->_tmp2_ = g_signal_connect_object (_data_->_tmp1_, "done", (GCallback) _deja_dup_tool_joblet_handle_done_tool_instance_done, _data_->self, 0);
	deja_dup_tool_joblet_add_handler (_data_->self, _data_->_tmp2_);
	_data_->_tmp3_ = _data_->self->priv->inst;
	_data_->_state_ = 1;
	tool_instance_start (_data_->_tmp3_, _data_->argv, _data_->envp, deja_dup_tool_joblet_start_inst_ready, _data_);
	return FALSE;
	_state_1:
	tool_instance_start_finish (_data_->_tmp3_, _data_->_res_);
	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
deja_dup_tool_joblet_real_handle_done (DejaDupToolJoblet* self,
                                       gboolean success,
                                       gboolean cancelled)
{
	if (self->priv->error_issued) {
		success = FALSE;
	} else {
		gboolean _tmp0_ = FALSE;
		gboolean _tmp1_ = FALSE;
		if (!success) {
			_tmp1_ = !cancelled;
		} else {
			_tmp1_ = FALSE;
		}
		if (_tmp1_) {
			_tmp0_ = !self->priv->error_issued;
		} else {
			_tmp0_ = FALSE;
		}
		if (_tmp0_) {
			g_signal_emit_by_name ((DejaDupToolJob*) self, "raise-error", _ ("Failed with an unknown error."), NULL);
		}
	}
	deja_dup_tool_joblet_disconnect_inst (self);
	g_signal_emit_by_name ((DejaDupToolJob*) self, "done", success, cancelled);
}

void
deja_dup_tool_joblet_handle_done (DejaDupToolJoblet* self,
                                  gboolean success,
                                  gboolean cancelled)
{
	DejaDupToolJobletClass* _klass_;
	g_return_if_fail (self != NULL);
	_klass_ = DEJA_DUP_TOOL_JOBLET_GET_CLASS (self);
	if (_klass_->handle_done) {
		_klass_->handle_done (self, success, cancelled);
	}
}

gchar*
deja_dup_tool_joblet_make_verification_error_message (const gchar* msg)
{
	gchar* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	gchar* _tmp5_;
	gchar* _tmp6_;
	gchar* _tmp7_;
	gchar* _tmp8_;
	gchar* _tmp9_;
	gchar* result;
	g_return_val_if_fail (msg != NULL, NULL);
	_tmp0_ = g_strdup_printf (_ ("An error occurred while validating your backup: ‘%s’."), msg);
	_tmp1_ = _tmp0_;
	_tmp2_ = g_strconcat (_tmp1_, "\n\n", NULL);
	_tmp3_ = _tmp2_;
	_tmp4_ = g_strconcat (_tmp3_, _ ("The backup might be corrupted."), NULL);
	_tmp5_ = _tmp4_;
	_tmp6_ = g_strconcat (_tmp5_, " ", NULL);
	_tmp7_ = _tmp6_;
	_tmp8_ = g_strconcat (_tmp7_, _ ("Please investigate the problem or start a new, separate backup."), NULL);
	_tmp9_ = _tmp8_;
	_g_free0 (_tmp7_);
	_g_free0 (_tmp5_);
	_g_free0 (_tmp3_);
	_g_free0 (_tmp1_);
	result = _tmp9_;
	return result;
}

DejaDupToolJoblet*
deja_dup_tool_joblet_construct (GType object_type)
{
	DejaDupToolJoblet * self = NULL;
	self = (DejaDupToolJoblet*) deja_dup_tool_job_construct (object_type);
	return self;
}

DejaDupToolJobChain*
deja_dup_tool_joblet_get_chain (DejaDupToolJoblet* self)
{
	DejaDupToolJobChain* result;
	DejaDupToolJobChain* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_chain;
	result = _tmp0_;
	return result;
}

void
deja_dup_tool_joblet_set_chain (DejaDupToolJoblet* self,
                                DejaDupToolJobChain* value)
{
	DejaDupToolJobChain* old_value;
	g_return_if_fail (self != NULL);
	old_value = deja_dup_tool_joblet_get_chain (self);
	if (old_value != value) {
		DejaDupToolJobChain* _tmp0_;
		_tmp0_ = _g_object_ref0 (value);
		_g_object_unref0 (self->priv->_chain);
		self->priv->_chain = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, deja_dup_tool_joblet_properties[DEJA_DUP_TOOL_JOBLET_CHAIN_PROPERTY]);
	}
}

static void
deja_dup_tool_joblet_class_init (DejaDupToolJobletClass * klass,
                                 gpointer klass_data)
{
	deja_dup_tool_joblet_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &DejaDupToolJoblet_private_offset);
	((DejaDupToolJobClass *) klass)->stop = (void (*) (DejaDupToolJob*)) deja_dup_tool_joblet_real_stop;
	((DejaDupToolJobClass *) klass)->pause = (void (*) (DejaDupToolJob*, const gchar*)) deja_dup_tool_joblet_real_pause;
	((DejaDupToolJobClass *) klass)->resume = (void (*) (DejaDupToolJob*)) deja_dup_tool_joblet_real_resume;
	((DejaDupToolJobClass *) klass)->start = (void (*) (DejaDupToolJob*, GAsyncReadyCallback, gpointer)) deja_dup_tool_joblet_real_start;
	((DejaDupToolJobClass *) klass)->start_finish = (void (*) (DejaDupToolJob*, GAsyncResult*)) deja_dup_tool_joblet_start_finish;
	((DejaDupToolJobletClass *) klass)->make_instance = (ToolInstance* (*) (DejaDupToolJoblet*)) deja_dup_tool_joblet_real_make_instance;
	((DejaDupToolJobletClass *) klass)->prepare_args = (void (*) (DejaDupToolJoblet*, GList**, GList**, GError**)) deja_dup_tool_joblet_real_prepare_args;
	((DejaDupToolJobletClass *) klass)->prepare = (void (*) (DejaDupToolJoblet*, GAsyncReadyCallback, gpointer)) deja_dup_tool_joblet_real_prepare;
	((DejaDupToolJobletClass *) klass)->prepare_finish = (void (*) (DejaDupToolJoblet*, GAsyncResult*, GError**)) deja_dup_tool_joblet_real_prepare_finish;
	((DejaDupToolJobletClass *) klass)->handle_done = (void (*) (DejaDupToolJoblet*, gboolean, gboolean)) deja_dup_tool_joblet_real_handle_done;
	G_OBJECT_CLASS (klass)->get_property = _vala_deja_dup_tool_joblet_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_deja_dup_tool_joblet_set_property;
	G_OBJECT_CLASS (klass)->finalize = deja_dup_tool_joblet_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), DEJA_DUP_TOOL_JOBLET_CHAIN_PROPERTY, deja_dup_tool_joblet_properties[DEJA_DUP_TOOL_JOBLET_CHAIN_PROPERTY] = g_param_spec_object ("chain", "chain", "chain", DEJA_DUP_TYPE_TOOL_JOB_CHAIN, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
}

static void
deja_dup_tool_joblet_instance_init (DejaDupToolJoblet * self,
                                    gpointer klass)
{
	self->priv = deja_dup_tool_joblet_get_instance_private (self);
}

static void
deja_dup_tool_joblet_finalize (GObject * obj)
{
	DejaDupToolJoblet * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, DEJA_DUP_TYPE_TOOL_JOBLET, DejaDupToolJoblet);
	_g_object_unref0 (self->priv->_chain);
	_g_object_unref0 (self->priv->inst);
	(self->priv->handlers == NULL) ? NULL : (self->priv->handlers = (g_list_free (self->priv->handlers), NULL));
	G_OBJECT_CLASS (deja_dup_tool_joblet_parent_class)->finalize (obj);
}

 G_GNUC_NO_INLINE static GType
deja_dup_tool_joblet_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (DejaDupToolJobletClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) deja_dup_tool_joblet_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DejaDupToolJoblet), 0, (GInstanceInitFunc) deja_dup_tool_joblet_instance_init, NULL };
	GType deja_dup_tool_joblet_type_id;
	deja_dup_tool_joblet_type_id = g_type_register_static (DEJA_DUP_TYPE_TOOL_JOB, "DejaDupToolJoblet", &g_define_type_info, G_TYPE_FLAG_ABSTRACT);
	DejaDupToolJoblet_private_offset = g_type_add_instance_private (deja_dup_tool_joblet_type_id, sizeof (DejaDupToolJobletPrivate));
	return deja_dup_tool_joblet_type_id;
}

GType
deja_dup_tool_joblet_get_type (void)
{
	static gsize deja_dup_tool_joblet_type_id__once = 0;
	if (g_once_init_enter (&deja_dup_tool_joblet_type_id__once)) {
		GType deja_dup_tool_joblet_type_id;
		deja_dup_tool_joblet_type_id = deja_dup_tool_joblet_get_type_once ();
		g_once_init_leave (&deja_dup_tool_joblet_type_id__once, deja_dup_tool_joblet_type_id);
	}
	return deja_dup_tool_joblet_type_id__once;
}

static void
_vala_deja_dup_tool_joblet_get_property (GObject * object,
                                         guint property_id,
                                         GValue * value,
                                         GParamSpec * pspec)
{
	DejaDupToolJoblet * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, DEJA_DUP_TYPE_TOOL_JOBLET, DejaDupToolJoblet);
	switch (property_id) {
		case DEJA_DUP_TOOL_JOBLET_CHAIN_PROPERTY:
		g_value_set_object (value, deja_dup_tool_joblet_get_chain (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_deja_dup_tool_joblet_set_property (GObject * object,
                                         guint property_id,
                                         const GValue * value,
                                         GParamSpec * pspec)
{
	DejaDupToolJoblet * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, DEJA_DUP_TYPE_TOOL_JOBLET, DejaDupToolJoblet);
	switch (property_id) {
		case DEJA_DUP_TOOL_JOBLET_CHAIN_PROPERTY:
		deja_dup_tool_joblet_set_chain (self, g_value_get_object (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

