/* vm-creator.c generated by valac 0.15.1.24-8065, the Vala compiler
 * generated from vm-creator.vala, do not modify */

/* This file is part of GNOME Boxes. License: LGPLv2+*/

#include <glib.h>
#include <glib-object.h>
#include <libvirt-gobject/libvirt-gobject.h>
#include <gio/gio.h>
#include <osinfo/osinfo.h>
#include <libvirt-gconfig/libvirt-gconfig.h>
#include <stdlib.h>
#include <string.h>
#include <config.h>
#include <gobject/gvaluecollector.h>


#define BOXES_TYPE_VM_CREATOR (boxes_vm_creator_get_type ())
#define BOXES_VM_CREATOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), BOXES_TYPE_VM_CREATOR, BoxesVMCreator))
#define BOXES_VM_CREATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), BOXES_TYPE_VM_CREATOR, BoxesVMCreatorClass))
#define BOXES_IS_VM_CREATOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), BOXES_TYPE_VM_CREATOR))
#define BOXES_IS_VM_CREATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), BOXES_TYPE_VM_CREATOR))
#define BOXES_VM_CREATOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), BOXES_TYPE_VM_CREATOR, BoxesVMCreatorClass))

typedef struct _BoxesVMCreator BoxesVMCreator;
typedef struct _BoxesVMCreatorClass BoxesVMCreatorClass;
typedef struct _BoxesVMCreatorPrivate BoxesVMCreatorPrivate;

#define BOXES_TYPE_VM_CONFIGURATOR (boxes_vm_configurator_get_type ())
#define BOXES_VM_CONFIGURATOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), BOXES_TYPE_VM_CONFIGURATOR, BoxesVMConfigurator))
#define BOXES_VM_CONFIGURATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), BOXES_TYPE_VM_CONFIGURATOR, BoxesVMConfiguratorClass))
#define BOXES_IS_VM_CONFIGURATOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), BOXES_TYPE_VM_CONFIGURATOR))
#define BOXES_IS_VM_CONFIGURATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), BOXES_TYPE_VM_CONFIGURATOR))
#define BOXES_VM_CONFIGURATOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), BOXES_TYPE_VM_CONFIGURATOR, BoxesVMConfiguratorClass))

typedef struct _BoxesVMConfigurator BoxesVMConfigurator;
typedef struct _BoxesVMConfiguratorClass BoxesVMConfiguratorClass;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _boxes_vm_configurator_unref0(var) ((var == NULL) ? NULL : (var = (boxes_vm_configurator_unref (var), NULL)))

#define BOXES_TYPE_UI (boxes_ui_get_type ())
#define BOXES_UI(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), BOXES_TYPE_UI, BoxesUI))
#define BOXES_UI_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), BOXES_TYPE_UI, BoxesUIClass))
#define BOXES_IS_UI(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), BOXES_TYPE_UI))
#define BOXES_IS_UI_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), BOXES_TYPE_UI))
#define BOXES_UI_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), BOXES_TYPE_UI, BoxesUIClass))

typedef struct _BoxesUI BoxesUI;
typedef struct _BoxesUIClass BoxesUIClass;

#define BOXES_TYPE_APP (boxes_app_get_type ())
#define BOXES_APP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), BOXES_TYPE_APP, BoxesApp))
#define BOXES_APP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), BOXES_TYPE_APP, BoxesAppClass))
#define BOXES_IS_APP(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), BOXES_TYPE_APP))
#define BOXES_IS_APP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), BOXES_TYPE_APP))
#define BOXES_APP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), BOXES_TYPE_APP, BoxesAppClass))

typedef struct _BoxesApp BoxesApp;
typedef struct _BoxesAppClass BoxesAppClass;
#define _boxes_vm_creator_unref0(var) ((var == NULL) ? NULL : (var = (boxes_vm_creator_unref (var), NULL)))

#define BOXES_TYPE_INSTALLER_MEDIA (boxes_installer_media_get_type ())
#define BOXES_INSTALLER_MEDIA(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), BOXES_TYPE_INSTALLER_MEDIA, BoxesInstallerMedia))
#define BOXES_INSTALLER_MEDIA_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), BOXES_TYPE_INSTALLER_MEDIA, BoxesInstallerMediaClass))
#define BOXES_IS_INSTALLER_MEDIA(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), BOXES_TYPE_INSTALLER_MEDIA))
#define BOXES_IS_INSTALLER_MEDIA_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), BOXES_TYPE_INSTALLER_MEDIA))
#define BOXES_INSTALLER_MEDIA_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), BOXES_TYPE_INSTALLER_MEDIA, BoxesInstallerMediaClass))

typedef struct _BoxesInstallerMedia BoxesInstallerMedia;
typedef struct _BoxesInstallerMediaClass BoxesInstallerMediaClass;
typedef struct _Block21Data Block21Data;

#define BOXES_TYPE_UNATTENDED_INSTALLER (boxes_unattended_installer_get_type ())
#define BOXES_UNATTENDED_INSTALLER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), BOXES_TYPE_UNATTENDED_INSTALLER, BoxesUnattendedInstaller))
#define BOXES_UNATTENDED_INSTALLER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), BOXES_TYPE_UNATTENDED_INSTALLER, BoxesUnattendedInstallerClass))
#define BOXES_IS_UNATTENDED_INSTALLER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), BOXES_TYPE_UNATTENDED_INSTALLER))
#define BOXES_IS_UNATTENDED_INSTALLER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), BOXES_TYPE_UNATTENDED_INSTALLER))
#define BOXES_UNATTENDED_INSTALLER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), BOXES_TYPE_UNATTENDED_INSTALLER, BoxesUnattendedInstallerClass))

typedef struct _BoxesUnattendedInstaller BoxesUnattendedInstaller;
typedef struct _BoxesUnattendedInstallerClass BoxesUnattendedInstallerClass;
typedef struct _BoxesInstallerMediaPrivate BoxesInstallerMediaPrivate;
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
typedef struct _BoxesVmCreatorCreateAndLaunchVmData BoxesVmCreatorCreateAndLaunchVmData;
#define __vala_GVirStorageVolInfo_free0(var) ((var == NULL) ? NULL : (var = (_vala_GVirStorageVolInfo_free (var), NULL)))
typedef struct _BoxesVmCreatorCreateTargetVolumeData BoxesVmCreatorCreateTargetVolumeData;
typedef struct _BoxesVmCreatorGetStoragePoolData BoxesVmCreatorGetStoragePoolData;
typedef struct _BoxesParamSpecVMCreator BoxesParamSpecVMCreator;

struct _BoxesVMCreator {
	GTypeInstance parent_instance;
	volatile int ref_count;
	BoxesVMCreatorPrivate * priv;
};

struct _BoxesVMCreatorClass {
	GTypeClass parent_class;
	void (*finalize) (BoxesVMCreator *self);
};

struct _BoxesVMCreatorPrivate {
	GVirConnection* connection;
	BoxesVMConfigurator* configurator;
};

struct _Block21Data {
	int _ref_count_;
	BoxesVMCreator * self;
	GVirStorageVol* volume;
	GVirConfigDomain* config;
	GVirDomain* domain;
	gulong id;
	BoxesInstallerMedia* install_media;
	gpointer _async_data_;
};

struct _BoxesInstallerMedia {
	GObject parent_instance;
	BoxesInstallerMediaPrivate * priv;
	OsinfoOs* os;
	OsinfoMedia* os_media;
	gchar* label;
	gchar* device_file;
	gchar* mount_point;
	gboolean from_image;
};

struct _BoxesInstallerMediaClass {
	GObjectClass parent_class;
};

struct _BoxesVmCreatorCreateAndLaunchVmData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GSimpleAsyncResult* _async_result;
	BoxesVMCreator* self;
	BoxesInstallerMedia* install_media;
	OsinfoResources* resources;
	GCancellable* cancellable;
	GVirDomain* result;
	Block21Data* _data21_;
	BoxesInstallerMedia* _tmp0_;
	BoxesInstallerMedia* _tmp1_;
	BoxesInstallerMedia* _tmp2_;
	BoxesInstallerMedia* _tmp3_;
	GCancellable* _tmp4_;
	gchar* name;
	BoxesInstallerMedia* _tmp5_;
	OsinfoOs* _tmp6_;
	BoxesInstallerMedia* _tmp7_;
	OsinfoOs* _tmp8_;
	const gchar* _tmp9_;
	const gchar* _tmp10_;
	gchar* _tmp11_;
	BoxesInstallerMedia* _tmp12_;
	const gchar* _tmp13_;
	gchar* _tmp14_;
	const gchar* _tmp15_;
	gchar* _tmp16_;
	gchar* domain_name;
	gint i;
	gboolean _tmp17_;
	gboolean _tmp18_;
	gint _tmp19_;
	GVirConnection* _tmp20_;
	const gchar* _tmp21_;
	GVirDomain* _tmp22_;
	GVirDomain* _tmp23_;
	gboolean _tmp24_;
	const gchar* _tmp25_;
	gchar* _tmp26_;
	gchar* _tmp27_;
	gint _tmp28_;
	gchar* _tmp29_;
	gchar* _tmp30_;
	gchar* _tmp31_;
	const gchar* _tmp32_;
	OsinfoResources* _tmp33_;
	gint64 _tmp34_;
	gint64 _tmp35_;
	GVirStorageVol* _tmp36_;
	BoxesVMConfigurator* _tmp37_;
	BoxesInstallerMedia* _tmp38_;
	const gchar* _tmp39_;
	GVirStorageVol* _tmp40_;
	const gchar* _tmp41_;
	OsinfoResources* _tmp42_;
	GVirConfigDomain* _tmp43_;
	BoxesInstallerMedia* _tmp44_;
	gboolean _tmp45_;
	gboolean _tmp46_;
	GVirConnection* _tmp47_;
	GVirConfigDomain* _tmp48_;
	GVirDomain* _tmp49_;
	GVirDomain* _tmp50_;
	GVirConnection* _tmp51_;
	GVirConfigDomain* _tmp52_;
	GVirDomain* _tmp53_;
	GVirDomain* _tmp54_;
	GVirDomain* _tmp55_;
	GVirDomain* _tmp56_;
	GVirConfigDomain* _tmp57_;
	GVirConfigDomain* _tmp58_;
	GVirDomain* _tmp59_;
	gulong _tmp60_;
	GVirDomain* _tmp61_;
	GVirDomain* _tmp62_;
	GError * _inner_error_;
};

struct _BoxesVmCreatorCreateTargetVolumeData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GSimpleAsyncResult* _async_result;
	BoxesVMCreator* self;
	gchar* name;
	gint64 storage;
	GVirStorageVol* result;
	GVirStoragePool* _tmp0_;
	GVirStoragePool* pool;
	const gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* volume_name;
	gint i;
	gboolean _tmp3_;
	gboolean _tmp4_;
	gint _tmp5_;
	GVirStoragePool* _tmp6_;
	const gchar* _tmp7_;
	GVirStoragePool* _tmp8_;
	GVirStoragePool* _tmp9_;
	gboolean _tmp10_;
	const gchar* _tmp11_;
	gchar* _tmp12_;
	gchar* _tmp13_;
	gint _tmp14_;
	gchar* _tmp15_;
	gchar* _tmp16_;
	gchar* _tmp17_;
	gchar* _tmp18_;
	gchar* _tmp19_;
	BoxesVMConfigurator* _tmp20_;
	const gchar* _tmp21_;
	gint64 _tmp22_;
	GVirConfigStorageVol* _tmp23_;
	GVirConfigStorageVol* config;
	GVirStoragePool* _tmp24_;
	GVirConfigStorageVol* _tmp25_;
	GVirStorageVol* _tmp26_;
	GVirStorageVol* volume;
	GError * _inner_error_;
};

struct _BoxesVmCreatorGetStoragePoolData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GSimpleAsyncResult* _async_result;
	BoxesVMCreator* self;
	GVirStoragePool* result;
	GVirConnection* _tmp0_;
	GVirStoragePool* _tmp1_;
	GVirStoragePool* pool;
	GVirStoragePool* _tmp2_;
	BoxesVMConfigurator* _tmp3_;
	GVirConfigStoragePool* _tmp4_;
	GVirConfigStoragePool* config;
	GVirConnection* _tmp5_;
	GVirConfigStoragePool* _tmp6_;
	GVirStoragePool* _tmp7_;
	GVirStoragePool* _tmp8_;
	GVirStoragePool* _tmp9_;
	GVirStoragePool* _tmp10_;
	GVirStoragePool* _tmp11_;
	GError * _inner_error_;
};

struct _BoxesParamSpecVMCreator {
	GParamSpec parent_instance;
};


static gpointer boxes_vm_creator_parent_class = NULL;

gpointer boxes_vm_creator_ref (gpointer instance);
void boxes_vm_creator_unref (gpointer instance);
GParamSpec* boxes_param_spec_vm_creator (const gchar* name, const gchar* nick, const gchar* blurb, GType object_type, GParamFlags flags);
void boxes_value_set_vm_creator (GValue* value, gpointer v_object);
void boxes_value_take_vm_creator (GValue* value, gpointer v_object);
gpointer boxes_value_get_vm_creator (const GValue* value);
GType boxes_vm_creator_get_type (void) G_GNUC_CONST;
gpointer boxes_vm_configurator_ref (gpointer instance);
void boxes_vm_configurator_unref (gpointer instance);
GParamSpec* boxes_param_spec_vm_configurator (const gchar* name, const gchar* nick, const gchar* blurb, GType object_type, GParamFlags flags);
void boxes_value_set_vm_configurator (GValue* value, gpointer v_object);
void boxes_value_take_vm_configurator (GValue* value, gpointer v_object);
gpointer boxes_value_get_vm_configurator (const GValue* value);
GType boxes_vm_configurator_get_type (void) G_GNUC_CONST;
#define BOXES_VM_CREATOR_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), BOXES_TYPE_VM_CREATOR, BoxesVMCreatorPrivate))
enum  {
	BOXES_VM_CREATOR_DUMMY_PROPERTY
};
GType boxes_ui_get_type (void) G_GNUC_CONST;
GType boxes_app_get_type (void) G_GNUC_CONST;
BoxesVMCreator* boxes_vm_creator_new (BoxesApp* app, GError** error);
BoxesVMCreator* boxes_vm_creator_construct (GType object_type, BoxesApp* app, GError** error);
GVirConnection* boxes_app_get_default_connection (BoxesApp* self);
BoxesVMConfigurator* boxes_vm_configurator_new (void);
BoxesVMConfigurator* boxes_vm_configurator_construct (GType object_type);
static void boxes_vm_creator_create_and_launch_vm_data_free (gpointer _data);
GType boxes_installer_media_get_type (void) G_GNUC_CONST;
void boxes_vm_creator_create_and_launch_vm (BoxesVMCreator* self, BoxesInstallerMedia* install_media, OsinfoResources* resources, GCancellable* cancellable, GAsyncReadyCallback _callback_, gpointer _user_data_);
GVirDomain* boxes_vm_creator_create_and_launch_vm_finish (BoxesVMCreator* self, GAsyncResult* _res_, GError** error);
static gboolean boxes_vm_creator_create_and_launch_vm_co (BoxesVmCreatorCreateAndLaunchVmData* _data_);
static Block21Data* block21_data_ref (Block21Data* _data21_);
static void block21_data_unref (void * _userdata_);
GType boxes_unattended_installer_get_type (void) G_GNUC_CONST;
void boxes_unattended_installer_setup (BoxesUnattendedInstaller* self, GCancellable* cancellable, GAsyncReadyCallback _callback_, gpointer _user_data_);
void boxes_unattended_installer_setup_finish (BoxesUnattendedInstaller* self, GAsyncResult* _res_, GError** error);
static void boxes_vm_creator_create_and_launch_vm_ready (GObject* source_object, GAsyncResult* _res_, gpointer _user_data_);
static void boxes_vm_creator_create_target_volume (BoxesVMCreator* self, const gchar* name, gint64 storage, GAsyncReadyCallback _callback_, gpointer _user_data_);
static GVirStorageVol* boxes_vm_creator_create_target_volume_finish (BoxesVMCreator* self, GAsyncResult* _res_, GError** error);
GVirConfigDomain* boxes_vm_configurator_create_domain_config (BoxesVMConfigurator* self, BoxesInstallerMedia* install_media, const gchar* name, const gchar* target_path, OsinfoResources* resources);
gboolean boxes_installer_media_get_live (BoxesInstallerMedia* self);
static void __lambda50_ (Block21Data* _data21_);
static gboolean boxes_vm_creator_guest_installed_os (BoxesVMCreator* self, GVirStorageVol* volume);
static void boxes_vm_creator_post_install_setup (BoxesVMCreator* self, GVirDomain* domain, GVirConfigDomain* config, gboolean permanent);
static void ___lambda50__gvir_domain_stopped (GVirDomain* _sender, gpointer self);
void boxes_vm_configurator_post_install_setup (BoxesVMConfigurator* self, GVirConfigDomain* domain);
static void _vala_GVirStorageVolInfo_free (GVirStorageVolInfo* self);
static void boxes_vm_creator_create_target_volume_data_free (gpointer _data);
static gboolean boxes_vm_creator_create_target_volume_co (BoxesVmCreatorCreateTargetVolumeData* _data_);
static void boxes_vm_creator_get_storage_pool (BoxesVMCreator* self, GAsyncReadyCallback _callback_, gpointer _user_data_);
static GVirStoragePool* boxes_vm_creator_get_storage_pool_finish (BoxesVMCreator* self, GAsyncResult* _res_, GError** error);
static void boxes_vm_creator_create_target_volume_ready (GObject* source_object, GAsyncResult* _res_, gpointer _user_data_);
GVirConfigStorageVol* boxes_vm_configurator_create_volume_config (BoxesVMConfigurator* self, const gchar* name, gint64 storage, GError** error);
static void boxes_vm_creator_get_storage_pool_data_free (gpointer _data);
static gboolean boxes_vm_creator_get_storage_pool_co (BoxesVmCreatorGetStoragePoolData* _data_);
GVirConfigStoragePool* boxes_vm_configurator_get_pool_config (BoxesVMConfigurator* self, GError** error);
static void boxes_vm_creator_get_storage_pool_ready (GObject* source_object, GAsyncResult* _res_, gpointer _user_data_);
static void boxes_vm_creator_finalize (BoxesVMCreator* obj);


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


BoxesVMCreator* boxes_vm_creator_construct (GType object_type, BoxesApp* app, GError** error) {
	BoxesVMCreator* self = NULL;
	BoxesApp* _tmp0_;
	GVirConnection* _tmp1_;
	GVirConnection* _tmp2_;
	GVirConnection* _tmp3_;
	BoxesVMConfigurator* _tmp4_;
	g_return_val_if_fail (app != NULL, NULL);
	self = (BoxesVMCreator*) g_type_create_instance (object_type);
	_tmp0_ = app;
	_tmp1_ = boxes_app_get_default_connection (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = _g_object_ref0 (_tmp2_);
	_g_object_unref0 (self->priv->connection);
	self->priv->connection = _tmp3_;
	_tmp4_ = boxes_vm_configurator_new ();
	_boxes_vm_configurator_unref0 (self->priv->configurator);
	self->priv->configurator = _tmp4_;
	return self;
}


BoxesVMCreator* boxes_vm_creator_new (BoxesApp* app, GError** error) {
	return boxes_vm_creator_construct (BOXES_TYPE_VM_CREATOR, app, error);
}


static void boxes_vm_creator_create_and_launch_vm_data_free (gpointer _data) {
	BoxesVmCreatorCreateAndLaunchVmData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->install_media);
	_g_object_unref0 (_data_->resources);
	_g_object_unref0 (_data_->cancellable);
	_g_object_unref0 (_data_->result);
	_boxes_vm_creator_unref0 (_data_->self);
	g_slice_free (BoxesVmCreatorCreateAndLaunchVmData, _data_);
}


static gpointer _boxes_vm_creator_ref0 (gpointer self) {
	return self ? boxes_vm_creator_ref (self) : NULL;
}


void boxes_vm_creator_create_and_launch_vm (BoxesVMCreator* self, BoxesInstallerMedia* install_media, OsinfoResources* resources, GCancellable* cancellable, GAsyncReadyCallback _callback_, gpointer _user_data_) {
	BoxesVmCreatorCreateAndLaunchVmData* _data_;
	BoxesVMCreator* _tmp0_;
	BoxesInstallerMedia* _tmp1_;
	BoxesInstallerMedia* _tmp2_;
	OsinfoResources* _tmp3_;
	OsinfoResources* _tmp4_;
	GCancellable* _tmp5_;
	GCancellable* _tmp6_;
	_data_ = g_slice_new0 (BoxesVmCreatorCreateAndLaunchVmData);
	_data_->_async_result = g_simple_async_result_new (g_object_newv (G_TYPE_OBJECT, 0, NULL), _callback_, _user_data_, boxes_vm_creator_create_and_launch_vm);
	g_simple_async_result_set_op_res_gpointer (_data_->_async_result, _data_, boxes_vm_creator_create_and_launch_vm_data_free);
	_tmp0_ = _boxes_vm_creator_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = install_media;
	_tmp2_ = _g_object_ref0 (_tmp1_);
	_data_->install_media = _tmp2_;
	_tmp3_ = resources;
	_tmp4_ = _g_object_ref0 (_tmp3_);
	_data_->resources = _tmp4_;
	_tmp5_ = cancellable;
	_tmp6_ = _g_object_ref0 (_tmp5_);
	_data_->cancellable = _tmp6_;
	boxes_vm_creator_create_and_launch_vm_co (_data_);
}


GVirDomain* boxes_vm_creator_create_and_launch_vm_finish (BoxesVMCreator* self, GAsyncResult* _res_, GError** error) {
	GVirDomain* result;
	BoxesVmCreatorCreateAndLaunchVmData* _data_;
	if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (_res_), error)) {
		return NULL;
	}
	_data_ = g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (_res_));
	result = _data_->result;
	_data_->result = NULL;
	return result;
}


static Block21Data* block21_data_ref (Block21Data* _data21_) {
	g_atomic_int_inc (&_data21_->_ref_count_);
	return _data21_;
}


static void block21_data_unref (void * _userdata_) {
	Block21Data* _data21_;
	_data21_ = (Block21Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data21_->_ref_count_)) {
		BoxesVMCreator * self;
		self = _data21_->self;
		_g_object_unref0 (_data21_->domain);
		_g_object_unref0 (_data21_->config);
		_g_object_unref0 (_data21_->volume);
		_g_object_unref0 (_data21_->install_media);
		_boxes_vm_creator_unref0 (self);
		g_slice_free (Block21Data, _data21_);
	}
}


static void boxes_vm_creator_create_and_launch_vm_ready (GObject* source_object, GAsyncResult* _res_, gpointer _user_data_) {
	BoxesVmCreatorCreateAndLaunchVmData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	boxes_vm_creator_create_and_launch_vm_co (_data_);
}


static void __lambda50_ (Block21Data* _data21_) {
	BoxesVMCreator * self;
	GVirStorageVol* _tmp0_;
	gboolean _tmp1_ = FALSE;
	GError * _inner_error_ = NULL;
	self = _data21_->self;
	_tmp0_ = _data21_->volume;
	_tmp1_ = boxes_vm_creator_guest_installed_os (self, _tmp0_);
	if (_tmp1_) {
		GVirDomain* _tmp2_;
		GVirConfigDomain* _tmp3_;
		BoxesInstallerMedia* _tmp4_;
		gboolean _tmp5_;
		gboolean _tmp6_;
		GVirDomain* _tmp7_;
		gulong _tmp8_;
		_tmp2_ = _data21_->domain;
		_tmp3_ = _data21_->config;
		_tmp4_ = _data21_->install_media;
		_tmp5_ = boxes_installer_media_get_live (_tmp4_);
		_tmp6_ = _tmp5_;
		boxes_vm_creator_post_install_setup (self, _tmp2_, _tmp3_, !_tmp6_);
		_tmp7_ = _data21_->domain;
		_tmp8_ = _data21_->id;
		g_signal_handler_disconnect ((GObject*) _tmp7_, _tmp8_);
	} else {
		BoxesInstallerMedia* _tmp9_;
		gboolean _tmp10_;
		gboolean _tmp11_;
		_tmp9_ = _data21_->install_media;
		_tmp10_ = boxes_installer_media_get_live (_tmp9_);
		_tmp11_ = _tmp10_;
		if (_tmp11_) {
			GVirDomain* _tmp12_;
			gulong _tmp13_;
			_tmp12_ = _data21_->domain;
			_tmp13_ = _data21_->id;
			g_signal_handler_disconnect ((GObject*) _tmp12_, _tmp13_);
			{
				GVirStorageVol* _tmp14_;
				_tmp14_ = _data21_->volume;
				gvir_storage_vol_delete (_tmp14_, (guint) 0, &_inner_error_);
				if (_inner_error_ != NULL) {
					goto __catch40_g_error;
				}
			}
			goto __finally40;
			__catch40_g_error:
			{
				GError* _error_ = NULL;
				GVirStorageVol* _tmp15_;
				const gchar* _tmp16_ = NULL;
				GError* _tmp17_;
				const gchar* _tmp18_;
				_error_ = _inner_error_;
				_inner_error_ = NULL;
				_tmp15_ = _data21_->volume;
				_tmp16_ = gvir_storage_vol_get_name (_tmp15_);
				_tmp17_ = _error_;
				_tmp18_ = _tmp17_->message;
				g_warning ("vm-creator.vala:55: Failed to delete volume '%s': %s", _tmp16_, _tmp18_);
				_g_error_free0 (_error_);
			}
			__finally40:
			if (_inner_error_ != NULL) {
				g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
				g_clear_error (&_inner_error_);
				return;
			}
		}
	}
}


static void ___lambda50__gvir_domain_stopped (GVirDomain* _sender, gpointer self) {
	__lambda50_ (self);
}


static gboolean boxes_vm_creator_create_and_launch_vm_co (BoxesVmCreatorCreateAndLaunchVmData* _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_->_data21_ = g_slice_new0 (Block21Data);
	_data_->_data21_->_ref_count_ = 1;
	_data_->_data21_->self = boxes_vm_creator_ref (_data_->self);
	_data_->_tmp0_ = _data_->install_media;
	_data_->_tmp1_ = _g_object_ref0 (_data_->_tmp0_);
	_data_->_data21_->install_media = _data_->_tmp1_;
	_data_->_data21_->_async_data_ = _data_;
	_data_->_tmp2_ = _data_->_data21_->install_media;
	if (BOXES_IS_UNATTENDED_INSTALLER (_data_->_tmp2_)) {
		_data_->_tmp3_ = _data_->_data21_->install_media;
		_data_->_tmp4_ = _data_->cancellable;
		_data_->_state_ = 1;
		boxes_unattended_installer_setup (BOXES_IS_UNATTENDED_INSTALLER (_data_->_tmp3_) ? ((BoxesUnattendedInstaller*) _data_->_tmp3_) : NULL, _data_->_tmp4_, boxes_vm_creator_create_and_launch_vm_ready, _data_);
		return FALSE;
		_state_1:
		boxes_unattended_installer_setup_finish (BOXES_IS_UNATTENDED_INSTALLER (_data_->_tmp3_) ? ((BoxesUnattendedInstaller*) _data_->_tmp3_) : NULL, _data_->_res_, &_data_->_inner_error_);
		if (_data_->_inner_error_ != NULL) {
			g_simple_async_result_set_from_error (_data_->_async_result, _data_->_inner_error_);
			g_error_free (_data_->_inner_error_);
			block21_data_unref (_data_->_data21_);
			_data_->_data21_ = NULL;
			if (_data_->_state_ == 0) {
				g_simple_async_result_complete_in_idle (_data_->_async_result);
			} else {
				g_simple_async_result_complete (_data_->_async_result);
			}
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
	}
	_data_->_tmp5_ = _data_->_data21_->install_media;
	_data_->_tmp6_ = _data_->_tmp5_->os;
	if (_data_->_tmp6_ != NULL) {
		_data_->_tmp7_ = _data_->_data21_->install_media;
		_data_->_tmp8_ = _data_->_tmp7_->os;
		_data_->_tmp9_ = osinfo_product_get_name ((OsinfoProduct*) _data_->_tmp8_);
		_data_->_tmp10_ = _data_->_tmp9_;
		_data_->_tmp11_ = g_strdup (_data_->_tmp10_);
		_g_free0 (_data_->name);
		_data_->name = _data_->_tmp11_;
	} else {
		_data_->_tmp12_ = _data_->_data21_->install_media;
		_data_->_tmp13_ = _data_->_tmp12_->label;
		_data_->_tmp14_ = g_strdup (_data_->_tmp13_);
		_g_free0 (_data_->name);
		_data_->name = _data_->_tmp14_;
	}
	_data_->_tmp15_ = _data_->name;
	_data_->_tmp16_ = g_strdup (_data_->_tmp15_);
	_data_->domain_name = _data_->_tmp16_;
	{
		_data_->i = 1;
		{
			_data_->_tmp17_ = TRUE;
			while (TRUE) {
				_data_->_tmp18_ = _data_->_tmp17_;
				if (!_data_->_tmp18_) {
					_data_->_tmp19_ = _data_->i;
					_data_->i = _data_->_tmp19_ + 1;
				}
				_data_->_tmp17_ = FALSE;
				_data_->_tmp20_ = _data_->self->priv->connection;
				_data_->_tmp21_ = _data_->domain_name;
				_data_->_tmp22_ = NULL;
				_data_->_tmp22_ = gvir_connection_find_domain_by_name (_data_->_tmp20_, _data_->_tmp21_);
				_data_->_tmp23_ = _data_->_tmp22_;
				_data_->_tmp24_ = !(_data_->_tmp23_ != NULL);
				_g_object_unref0 (_data_->_tmp23_);
				if (_data_->_tmp24_) {
					break;
				}
				_data_->_tmp25_ = _data_->name;
				_data_->_tmp26_ = g_strconcat (_data_->_tmp25_, "-", NULL);
				_data_->_tmp27_ = _data_->_tmp26_;
				_data_->_tmp28_ = _data_->i;
				_data_->_tmp29_ = NULL;
				_data_->_tmp29_ = g_strdup_printf ("%i", _data_->_tmp28_);
				_data_->_tmp30_ = _data_->_tmp29_;
				_data_->_tmp31_ = g_strconcat (_data_->_tmp27_, _data_->_tmp30_, NULL);
				_g_free0 (_data_->domain_name);
				_data_->domain_name = _data_->_tmp31_;
				_g_free0 (_data_->_tmp30_);
				_g_free0 (_data_->_tmp27_);
			}
		}
	}
	_data_->_tmp32_ = _data_->name;
	_data_->_tmp33_ = _data_->resources;
	_data_->_tmp34_ = osinfo_resources_get_storage (_data_->_tmp33_);
	_data_->_tmp35_ = _data_->_tmp34_;
	_data_->_state_ = 2;
	boxes_vm_creator_create_target_volume (_data_->self, _data_->_tmp32_, _data_->_tmp35_, boxes_vm_creator_create_and_launch_vm_ready, _data_);
	return FALSE;
	_state_2:
	_data_->_tmp36_ = NULL;
	_data_->_tmp36_ = boxes_vm_creator_create_target_volume_finish (_data_->self, _data_->_res_, &_data_->_inner_error_);
	_data_->_data21_->volume = _data_->_tmp36_;
	if (_data_->_inner_error_ != NULL) {
		g_simple_async_result_set_from_error (_data_->_async_result, _data_->_inner_error_);
		g_error_free (_data_->_inner_error_);
		_g_free0 (_data_->domain_name);
		_g_free0 (_data_->name);
		block21_data_unref (_data_->_data21_);
		_data_->_data21_ = NULL;
		if (_data_->_state_ == 0) {
			g_simple_async_result_complete_in_idle (_data_->_async_result);
		} else {
			g_simple_async_result_complete (_data_->_async_result);
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp37_ = _data_->self->priv->configurator;
	_data_->_tmp38_ = _data_->_data21_->install_media;
	_data_->_tmp39_ = _data_->domain_name;
	_data_->_tmp40_ = _data_->_data21_->volume;
	_data_->_tmp41_ = NULL;
	_data_->_tmp41_ = gvir_storage_vol_get_path (_data_->_tmp40_);
	_data_->_tmp42_ = _data_->resources;
	_data_->_tmp43_ = NULL;
	_data_->_tmp43_ = boxes_vm_configurator_create_domain_config (_data_->_tmp37_, _data_->_tmp38_, _data_->_tmp39_, _data_->_tmp41_, _data_->_tmp42_);
	_data_->_data21_->config = _data_->_tmp43_;
	_data_->_tmp44_ = _data_->_data21_->install_media;
	_data_->_tmp45_ = boxes_installer_media_get_live (_data_->_tmp44_);
	_data_->_tmp46_ = _data_->_tmp45_;
	if (_data_->_tmp46_) {
		_data_->_tmp47_ = _data_->self->priv->connection;
		_data_->_tmp48_ = _data_->_data21_->config;
		_data_->_tmp49_ = NULL;
		_data_->_tmp49_ = gvir_connection_start_domain (_data_->_tmp47_, _data_->_tmp48_, (guint) 0, &_data_->_inner_error_);
		_data_->_tmp50_ = _data_->_tmp49_;
		if (_data_->_inner_error_ != NULL) {
			g_simple_async_result_set_from_error (_data_->_async_result, _data_->_inner_error_);
			g_error_free (_data_->_inner_error_);
			_g_free0 (_data_->domain_name);
			_g_free0 (_data_->name);
			block21_data_unref (_data_->_data21_);
			_data_->_data21_ = NULL;
			if (_data_->_state_ == 0) {
				g_simple_async_result_complete_in_idle (_data_->_async_result);
			} else {
				g_simple_async_result_complete (_data_->_async_result);
			}
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
		_g_object_unref0 (_data_->_data21_->domain);
		_data_->_data21_->domain = _data_->_tmp50_;
	} else {
		_data_->_tmp51_ = _data_->self->priv->connection;
		_data_->_tmp52_ = _data_->_data21_->config;
		_data_->_tmp53_ = NULL;
		_data_->_tmp53_ = gvir_connection_create_domain (_data_->_tmp51_, _data_->_tmp52_, &_data_->_inner_error_);
		_data_->_tmp54_ = _data_->_tmp53_;
		if (_data_->_inner_error_ != NULL) {
			g_simple_async_result_set_from_error (_data_->_async_result, _data_->_inner_error_);
			g_error_free (_data_->_inner_error_);
			_g_free0 (_data_->domain_name);
			_g_free0 (_data_->name);
			block21_data_unref (_data_->_data21_);
			_data_->_data21_ = NULL;
			if (_data_->_state_ == 0) {
				g_simple_async_result_complete_in_idle (_data_->_async_result);
			} else {
				g_simple_async_result_complete (_data_->_async_result);
			}
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
		_g_object_unref0 (_data_->_data21_->domain);
		_data_->_data21_->domain = _data_->_tmp54_;
		_data_->_tmp55_ = _data_->_data21_->domain;
		gvir_domain_start (_data_->_tmp55_, (guint) 0, &_data_->_inner_error_);
		if (_data_->_inner_error_ != NULL) {
			g_simple_async_result_set_from_error (_data_->_async_result, _data_->_inner_error_);
			g_error_free (_data_->_inner_error_);
			_g_free0 (_data_->domain_name);
			_g_free0 (_data_->name);
			block21_data_unref (_data_->_data21_);
			_data_->_data21_ = NULL;
			if (_data_->_state_ == 0) {
				g_simple_async_result_complete_in_idle (_data_->_async_result);
			} else {
				g_simple_async_result_complete (_data_->_async_result);
			}
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
		_data_->_tmp56_ = _data_->_data21_->domain;
		_data_->_tmp57_ = NULL;
		_data_->_tmp57_ = gvir_domain_get_config (_data_->_tmp56_, (guint) 0, &_data_->_inner_error_);
		_data_->_tmp58_ = _data_->_tmp57_;
		if (_data_->_inner_error_ != NULL) {
			g_simple_async_result_set_from_error (_data_->_async_result, _data_->_inner_error_);
			g_error_free (_data_->_inner_error_);
			_g_free0 (_data_->domain_name);
			_g_free0 (_data_->name);
			block21_data_unref (_data_->_data21_);
			_data_->_data21_ = NULL;
			if (_data_->_state_ == 0) {
				g_simple_async_result_complete_in_idle (_data_->_async_result);
			} else {
				g_simple_async_result_complete (_data_->_async_result);
			}
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
		_g_object_unref0 (_data_->_data21_->config);
		_data_->_data21_->config = _data_->_tmp58_;
	}
	_data_->_data21_->id = (gulong) 0;
	_data_->_tmp59_ = _data_->_data21_->domain;
	_data_->_tmp60_ = 0UL;
	_data_->_tmp60_ = g_signal_connect_data (_data_->_tmp59_, "stopped", (GCallback) ___lambda50__gvir_domain_stopped, block21_data_ref (_data_->_data21_), (GClosureNotify) block21_data_unref, 0);
	_data_->_data21_->id = _data_->_tmp60_;
	_data_->_tmp61_ = _data_->_data21_->domain;
	_data_->_tmp62_ = _g_object_ref0 (_data_->_tmp61_);
	_data_->result = _data_->_tmp62_;
	_g_free0 (_data_->domain_name);
	_g_free0 (_data_->name);
	block21_data_unref (_data_->_data21_);
	_data_->_data21_ = NULL;
	if (_data_->_state_ == 0) {
		g_simple_async_result_complete_in_idle (_data_->_async_result);
	} else {
		g_simple_async_result_complete (_data_->_async_result);
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
	_g_free0 (_data_->domain_name);
	_g_free0 (_data_->name);
	block21_data_unref (_data_->_data21_);
	_data_->_data21_ = NULL;
	if (_data_->_state_ == 0) {
		g_simple_async_result_complete_in_idle (_data_->_async_result);
	} else {
		g_simple_async_result_complete (_data_->_async_result);
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}


static void boxes_vm_creator_post_install_setup (BoxesVMCreator* self, GVirDomain* domain, GVirConfigDomain* config, gboolean permanent) {
	BoxesVMConfigurator* _tmp0_;
	GVirConfigDomain* _tmp1_;
	GError * _inner_error_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (domain != NULL);
	g_return_if_fail (config != NULL);
	_tmp0_ = self->priv->configurator;
	_tmp1_ = config;
	boxes_vm_configurator_post_install_setup (_tmp0_, _tmp1_);
	{
		gboolean _tmp2_;
		_tmp2_ = permanent;
		if (_tmp2_) {
			GVirDomain* _tmp3_;
			GVirConfigDomain* _tmp4_;
			GVirDomain* _tmp5_;
			_tmp3_ = domain;
			_tmp4_ = config;
			gvir_domain_set_config (_tmp3_, _tmp4_, &_inner_error_);
			if (_inner_error_ != NULL) {
				goto __catch41_g_error;
			}
			_tmp5_ = domain;
			gvir_domain_start (_tmp5_, (guint) 0, &_inner_error_);
			if (_inner_error_ != NULL) {
				goto __catch41_g_error;
			}
		} else {
			GVirConnection* _tmp6_;
			GVirConfigDomain* _tmp7_;
			GVirDomain* _tmp8_ = NULL;
			GVirDomain* new_domain;
			GVirDomain* _tmp9_;
			_tmp6_ = self->priv->connection;
			_tmp7_ = config;
			_tmp8_ = gvir_connection_create_domain (_tmp6_, _tmp7_, &_inner_error_);
			new_domain = _tmp8_;
			if (_inner_error_ != NULL) {
				goto __catch41_g_error;
			}
			_tmp9_ = new_domain;
			gvir_domain_start (_tmp9_, (guint) 0, &_inner_error_);
			if (_inner_error_ != NULL) {
				_g_object_unref0 (new_domain);
				goto __catch41_g_error;
			}
			_g_object_unref0 (new_domain);
		}
	}
	goto __finally41;
	__catch41_g_error:
	{
		GError* _error_ = NULL;
		GVirDomain* _tmp10_;
		const gchar* _tmp11_ = NULL;
		GError* _tmp12_;
		const gchar* _tmp13_;
		_error_ = _inner_error_;
		_inner_error_ = NULL;
		_tmp10_ = domain;
		_tmp11_ = gvir_domain_get_uuid (_tmp10_);
		_tmp12_ = _error_;
		_tmp13_ = _tmp12_->message;
		g_warning ("vm-creator.vala:75: Post-install setup failed for domain '%s': %s", _tmp11_, _tmp13_);
		_g_error_free0 (_error_);
	}
	__finally41:
	if (_inner_error_ != NULL) {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
		g_clear_error (&_inner_error_);
		return;
	}
}


static void _vala_GVirStorageVolInfo_free (GVirStorageVolInfo* self) {
	g_boxed_free (gvir_storage_vol_info_get_type (), self);
}


static gboolean boxes_vm_creator_guest_installed_os (BoxesVMCreator* self, GVirStorageVol* volume) {
	gboolean result = FALSE;
	GError * _inner_error_ = NULL;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (volume != NULL, FALSE);
	{
		GVirStorageVol* _tmp0_;
		GVirStorageVolInfo* _tmp1_ = NULL;
		GVirStorageVolInfo* info;
		guint64 _tmp2_;
		_tmp0_ = volume;
		_tmp1_ = gvir_storage_vol_get_info (_tmp0_, &_inner_error_);
		info = _tmp1_;
		if (_inner_error_ != NULL) {
			goto __catch42_g_error;
		}
		_tmp2_ = info->allocation;
		result = _tmp2_ >= ((guint64) OSINFO_MEBIBYTES);
		__vala_GVirStorageVolInfo_free0 (info);
		return result;
	}
	goto __finally42;
	__catch42_g_error:
	{
		GError* _error_ = NULL;
		GVirStorageVol* _tmp3_;
		const gchar* _tmp4_ = NULL;
		GError* _tmp5_;
		const gchar* _tmp6_;
		_error_ = _inner_error_;
		_inner_error_ = NULL;
		_tmp3_ = volume;
		_tmp4_ = gvir_storage_vol_get_name (_tmp3_);
		_tmp5_ = _error_;
		_tmp6_ = _tmp5_->message;
		g_warning ("vm-creator.vala:86: Failed to get information from volume '%s': %s", _tmp4_, _tmp6_);
		result = FALSE;
		_g_error_free0 (_error_);
		return result;
	}
	__finally42:
	g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
	g_clear_error (&_inner_error_);
	return FALSE;
}


static void boxes_vm_creator_create_target_volume_data_free (gpointer _data) {
	BoxesVmCreatorCreateTargetVolumeData* _data_;
	_data_ = _data;
	_g_free0 (_data_->name);
	_g_object_unref0 (_data_->result);
	_boxes_vm_creator_unref0 (_data_->self);
	g_slice_free (BoxesVmCreatorCreateTargetVolumeData, _data_);
}


static void boxes_vm_creator_create_target_volume (BoxesVMCreator* self, const gchar* name, gint64 storage, GAsyncReadyCallback _callback_, gpointer _user_data_) {
	BoxesVmCreatorCreateTargetVolumeData* _data_;
	BoxesVMCreator* _tmp0_;
	const gchar* _tmp1_;
	gchar* _tmp2_;
	gint64 _tmp3_;
	_data_ = g_slice_new0 (BoxesVmCreatorCreateTargetVolumeData);
	_data_->_async_result = g_simple_async_result_new (g_object_newv (G_TYPE_OBJECT, 0, NULL), _callback_, _user_data_, boxes_vm_creator_create_target_volume);
	g_simple_async_result_set_op_res_gpointer (_data_->_async_result, _data_, boxes_vm_creator_create_target_volume_data_free);
	_tmp0_ = _boxes_vm_creator_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = name;
	_tmp2_ = g_strdup (_tmp1_);
	_data_->name = _tmp2_;
	_tmp3_ = storage;
	_data_->storage = _tmp3_;
	boxes_vm_creator_create_target_volume_co (_data_);
}


static GVirStorageVol* boxes_vm_creator_create_target_volume_finish (BoxesVMCreator* self, GAsyncResult* _res_, GError** error) {
	GVirStorageVol* result;
	BoxesVmCreatorCreateTargetVolumeData* _data_;
	if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (_res_), error)) {
		return NULL;
	}
	_data_ = g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (_res_));
	result = _data_->result;
	_data_->result = NULL;
	return result;
}


static void boxes_vm_creator_create_target_volume_ready (GObject* source_object, GAsyncResult* _res_, gpointer _user_data_) {
	BoxesVmCreatorCreateTargetVolumeData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	boxes_vm_creator_create_target_volume_co (_data_);
}


static gboolean boxes_vm_creator_create_target_volume_co (BoxesVmCreatorCreateTargetVolumeData* _data_) {
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_state_ = 1;
	boxes_vm_creator_get_storage_pool (_data_->self, boxes_vm_creator_create_target_volume_ready, _data_);
	return FALSE;
	_state_1:
	_data_->_tmp0_ = NULL;
	_data_->_tmp0_ = boxes_vm_creator_get_storage_pool_finish (_data_->self, _data_->_res_, &_data_->_inner_error_);
	_data_->pool = _data_->_tmp0_;
	if (_data_->_inner_error_ != NULL) {
		g_simple_async_result_set_from_error (_data_->_async_result, _data_->_inner_error_);
		g_error_free (_data_->_inner_error_);
		if (_data_->_state_ == 0) {
			g_simple_async_result_complete_in_idle (_data_->_async_result);
		} else {
			g_simple_async_result_complete (_data_->_async_result);
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp1_ = _data_->name;
	_data_->_tmp2_ = g_strconcat (_data_->_tmp1_, ".qcow2", NULL);
	_data_->volume_name = _data_->_tmp2_;
	{
		_data_->i = 1;
		{
			_data_->_tmp3_ = TRUE;
			while (TRUE) {
				_data_->_tmp4_ = _data_->_tmp3_;
				if (!_data_->_tmp4_) {
					_data_->_tmp5_ = _data_->i;
					_data_->i = _data_->_tmp5_ + 1;
				}
				_data_->_tmp3_ = FALSE;
				_data_->_tmp6_ = _data_->pool;
				_data_->_tmp7_ = _data_->volume_name;
				_data_->_tmp8_ = NULL;
				_data_->_tmp8_ = gvir_storage_pool_get_volume (_data_->_tmp6_, _data_->_tmp7_);
				_data_->_tmp9_ = _data_->_tmp8_;
				_data_->_tmp10_ = !(_data_->_tmp9_ != NULL);
				_g_object_unref0 (_data_->_tmp9_);
				if (_data_->_tmp10_) {
					break;
				}
				_data_->_tmp11_ = _data_->name;
				_data_->_tmp12_ = g_strconcat (_data_->_tmp11_, "-", NULL);
				_data_->_tmp13_ = _data_->_tmp12_;
				_data_->_tmp14_ = _data_->i;
				_data_->_tmp15_ = NULL;
				_data_->_tmp15_ = g_strdup_printf ("%i", _data_->_tmp14_);
				_data_->_tmp16_ = _data_->_tmp15_;
				_data_->_tmp17_ = g_strconcat (_data_->_tmp13_, _data_->_tmp16_, NULL);
				_data_->_tmp18_ = _data_->_tmp17_;
				_data_->_tmp19_ = g_strconcat (_data_->_tmp18_, ".qcow2", NULL);
				_g_free0 (_data_->volume_name);
				_data_->volume_name = _data_->_tmp19_;
				_g_free0 (_data_->_tmp18_);
				_g_free0 (_data_->_tmp16_);
				_g_free0 (_data_->_tmp13_);
			}
		}
	}
	_data_->_tmp20_ = _data_->self->priv->configurator;
	_data_->_tmp21_ = _data_->volume_name;
	_data_->_tmp22_ = _data_->storage;
	_data_->_tmp23_ = NULL;
	_data_->_tmp23_ = boxes_vm_configurator_create_volume_config (_data_->_tmp20_, _data_->_tmp21_, _data_->_tmp22_, &_data_->_inner_error_);
	_data_->config = _data_->_tmp23_;
	if (_data_->_inner_error_ != NULL) {
		g_simple_async_result_set_from_error (_data_->_async_result, _data_->_inner_error_);
		g_error_free (_data_->_inner_error_);
		_g_free0 (_data_->volume_name);
		_g_object_unref0 (_data_->pool);
		if (_data_->_state_ == 0) {
			g_simple_async_result_complete_in_idle (_data_->_async_result);
		} else {
			g_simple_async_result_complete (_data_->_async_result);
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp24_ = _data_->pool;
	_data_->_tmp25_ = _data_->config;
	_data_->_tmp26_ = NULL;
	_data_->_tmp26_ = gvir_storage_pool_create_volume (_data_->_tmp24_, _data_->_tmp25_, &_data_->_inner_error_);
	_data_->volume = _data_->_tmp26_;
	if (_data_->_inner_error_ != NULL) {
		g_simple_async_result_set_from_error (_data_->_async_result, _data_->_inner_error_);
		g_error_free (_data_->_inner_error_);
		_g_object_unref0 (_data_->config);
		_g_free0 (_data_->volume_name);
		_g_object_unref0 (_data_->pool);
		if (_data_->_state_ == 0) {
			g_simple_async_result_complete_in_idle (_data_->_async_result);
		} else {
			g_simple_async_result_complete (_data_->_async_result);
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->result = _data_->volume;
	_g_object_unref0 (_data_->config);
	_g_free0 (_data_->volume_name);
	_g_object_unref0 (_data_->pool);
	if (_data_->_state_ == 0) {
		g_simple_async_result_complete_in_idle (_data_->_async_result);
	} else {
		g_simple_async_result_complete (_data_->_async_result);
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
	_g_object_unref0 (_data_->volume);
	_g_object_unref0 (_data_->config);
	_g_free0 (_data_->volume_name);
	_g_object_unref0 (_data_->pool);
	if (_data_->_state_ == 0) {
		g_simple_async_result_complete_in_idle (_data_->_async_result);
	} else {
		g_simple_async_result_complete (_data_->_async_result);
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}


static void boxes_vm_creator_get_storage_pool_data_free (gpointer _data) {
	BoxesVmCreatorGetStoragePoolData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->result);
	_boxes_vm_creator_unref0 (_data_->self);
	g_slice_free (BoxesVmCreatorGetStoragePoolData, _data_);
}


static void boxes_vm_creator_get_storage_pool (BoxesVMCreator* self, GAsyncReadyCallback _callback_, gpointer _user_data_) {
	BoxesVmCreatorGetStoragePoolData* _data_;
	BoxesVMCreator* _tmp0_;
	_data_ = g_slice_new0 (BoxesVmCreatorGetStoragePoolData);
	_data_->_async_result = g_simple_async_result_new (g_object_newv (G_TYPE_OBJECT, 0, NULL), _callback_, _user_data_, boxes_vm_creator_get_storage_pool);
	g_simple_async_result_set_op_res_gpointer (_data_->_async_result, _data_, boxes_vm_creator_get_storage_pool_data_free);
	_tmp0_ = _boxes_vm_creator_ref0 (self);
	_data_->self = _tmp0_;
	boxes_vm_creator_get_storage_pool_co (_data_);
}


static GVirStoragePool* boxes_vm_creator_get_storage_pool_finish (BoxesVMCreator* self, GAsyncResult* _res_, GError** error) {
	GVirStoragePool* result;
	BoxesVmCreatorGetStoragePoolData* _data_;
	if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (_res_), error)) {
		return NULL;
	}
	_data_ = g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (_res_));
	result = _data_->result;
	_data_->result = NULL;
	return result;
}


static void boxes_vm_creator_get_storage_pool_ready (GObject* source_object, GAsyncResult* _res_, gpointer _user_data_) {
	BoxesVmCreatorGetStoragePoolData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	boxes_vm_creator_get_storage_pool_co (_data_);
}


static gboolean boxes_vm_creator_get_storage_pool_co (BoxesVmCreatorGetStoragePoolData* _data_) {
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		case 2:
		goto _state_2;
		case 3:
		goto _state_3;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = _data_->self->priv->connection;
	_data_->_tmp1_ = NULL;
	_data_->_tmp1_ = gvir_connection_find_storage_pool_by_name (_data_->_tmp0_, PACKAGE_TARNAME);
	_data_->pool = _data_->_tmp1_;
	_data_->_tmp2_ = _data_->pool;
	if (_data_->_tmp2_ == NULL) {
		_data_->_tmp3_ = _data_->self->priv->configurator;
		_data_->_tmp4_ = NULL;
		_data_->_tmp4_ = boxes_vm_configurator_get_pool_config (_data_->_tmp3_, &_data_->_inner_error_);
		_data_->config = _data_->_tmp4_;
		if (_data_->_inner_error_ != NULL) {
			g_simple_async_result_set_from_error (_data_->_async_result, _data_->_inner_error_);
			g_error_free (_data_->_inner_error_);
			_g_object_unref0 (_data_->pool);
			if (_data_->_state_ == 0) {
				g_simple_async_result_complete_in_idle (_data_->_async_result);
			} else {
				g_simple_async_result_complete (_data_->_async_result);
			}
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
		_data_->_tmp5_ = _data_->self->priv->connection;
		_data_->_tmp6_ = _data_->config;
		_data_->_tmp7_ = NULL;
		_data_->_tmp7_ = gvir_connection_create_storage_pool (_data_->_tmp5_, _data_->_tmp6_, (guint) 0, &_data_->_inner_error_);
		_data_->_tmp8_ = _data_->_tmp7_;
		if (_data_->_inner_error_ != NULL) {
			g_simple_async_result_set_from_error (_data_->_async_result, _data_->_inner_error_);
			g_error_free (_data_->_inner_error_);
			_g_object_unref0 (_data_->config);
			_g_object_unref0 (_data_->pool);
			if (_data_->_state_ == 0) {
				g_simple_async_result_complete_in_idle (_data_->_async_result);
			} else {
				g_simple_async_result_complete (_data_->_async_result);
			}
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
		_g_object_unref0 (_data_->pool);
		_data_->pool = _data_->_tmp8_;
		_data_->_tmp9_ = _data_->pool;
		_data_->_state_ = 1;
		gvir_storage_pool_build_async (_data_->_tmp9_, (guint) 0, NULL, boxes_vm_creator_get_storage_pool_ready, _data_);
		return FALSE;
		_state_1:
		gvir_storage_pool_build_finish (_data_->_tmp9_, _data_->_res_, &_data_->_inner_error_);
		if (_data_->_inner_error_ != NULL) {
			g_simple_async_result_set_from_error (_data_->_async_result, _data_->_inner_error_);
			g_error_free (_data_->_inner_error_);
			_g_object_unref0 (_data_->config);
			_g_object_unref0 (_data_->pool);
			if (_data_->_state_ == 0) {
				g_simple_async_result_complete_in_idle (_data_->_async_result);
			} else {
				g_simple_async_result_complete (_data_->_async_result);
			}
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
		_data_->_tmp10_ = _data_->pool;
		_data_->_state_ = 2;
		gvir_storage_pool_start_async (_data_->_tmp10_, (guint) 0, NULL, boxes_vm_creator_get_storage_pool_ready, _data_);
		return FALSE;
		_state_2:
		gvir_storage_pool_start_finish (_data_->_tmp10_, _data_->_res_, &_data_->_inner_error_);
		if (_data_->_inner_error_ != NULL) {
			g_simple_async_result_set_from_error (_data_->_async_result, _data_->_inner_error_);
			g_error_free (_data_->_inner_error_);
			_g_object_unref0 (_data_->config);
			_g_object_unref0 (_data_->pool);
			if (_data_->_state_ == 0) {
				g_simple_async_result_complete_in_idle (_data_->_async_result);
			} else {
				g_simple_async_result_complete (_data_->_async_result);
			}
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
		_data_->_tmp11_ = _data_->pool;
		_data_->_state_ = 3;
		gvir_storage_pool_refresh_async (_data_->_tmp11_, NULL, boxes_vm_creator_get_storage_pool_ready, _data_);
		return FALSE;
		_state_3:
		gvir_storage_pool_refresh_finish (_data_->_tmp11_, _data_->_res_, &_data_->_inner_error_);
		if (_data_->_inner_error_ != NULL) {
			g_simple_async_result_set_from_error (_data_->_async_result, _data_->_inner_error_);
			g_error_free (_data_->_inner_error_);
			_g_object_unref0 (_data_->config);
			_g_object_unref0 (_data_->pool);
			if (_data_->_state_ == 0) {
				g_simple_async_result_complete_in_idle (_data_->_async_result);
			} else {
				g_simple_async_result_complete (_data_->_async_result);
			}
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
		_g_object_unref0 (_data_->config);
	}
	_data_->result = _data_->pool;
	if (_data_->_state_ == 0) {
		g_simple_async_result_complete_in_idle (_data_->_async_result);
	} else {
		g_simple_async_result_complete (_data_->_async_result);
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
	_g_object_unref0 (_data_->pool);
	if (_data_->_state_ == 0) {
		g_simple_async_result_complete_in_idle (_data_->_async_result);
	} else {
		g_simple_async_result_complete (_data_->_async_result);
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}


static void boxes_value_vm_creator_init (GValue* value) {
	value->data[0].v_pointer = NULL;
}


static void boxes_value_vm_creator_free_value (GValue* value) {
	if (value->data[0].v_pointer) {
		boxes_vm_creator_unref (value->data[0].v_pointer);
	}
}


static void boxes_value_vm_creator_copy_value (const GValue* src_value, GValue* dest_value) {
	if (src_value->data[0].v_pointer) {
		dest_value->data[0].v_pointer = boxes_vm_creator_ref (src_value->data[0].v_pointer);
	} else {
		dest_value->data[0].v_pointer = NULL;
	}
}


static gpointer boxes_value_vm_creator_peek_pointer (const GValue* value) {
	return value->data[0].v_pointer;
}


static gchar* boxes_value_vm_creator_collect_value (GValue* value, guint n_collect_values, GTypeCValue* collect_values, guint collect_flags) {
	if (collect_values[0].v_pointer) {
		BoxesVMCreator* object;
		object = collect_values[0].v_pointer;
		if (object->parent_instance.g_class == NULL) {
			return g_strconcat ("invalid unclassed object pointer for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		} else if (!g_value_type_compatible (G_TYPE_FROM_INSTANCE (object), G_VALUE_TYPE (value))) {
			return g_strconcat ("invalid object type `", g_type_name (G_TYPE_FROM_INSTANCE (object)), "' for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		}
		value->data[0].v_pointer = boxes_vm_creator_ref (object);
	} else {
		value->data[0].v_pointer = NULL;
	}
	return NULL;
}


static gchar* boxes_value_vm_creator_lcopy_value (const GValue* value, guint n_collect_values, GTypeCValue* collect_values, guint collect_flags) {
	BoxesVMCreator** object_p;
	object_p = collect_values[0].v_pointer;
	if (!object_p) {
		return g_strdup_printf ("value location for `%s' passed as NULL", G_VALUE_TYPE_NAME (value));
	}
	if (!value->data[0].v_pointer) {
		*object_p = NULL;
	} else if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
		*object_p = value->data[0].v_pointer;
	} else {
		*object_p = boxes_vm_creator_ref (value->data[0].v_pointer);
	}
	return NULL;
}


GParamSpec* boxes_param_spec_vm_creator (const gchar* name, const gchar* nick, const gchar* blurb, GType object_type, GParamFlags flags) {
	BoxesParamSpecVMCreator* spec;
	g_return_val_if_fail (g_type_is_a (object_type, BOXES_TYPE_VM_CREATOR), NULL);
	spec = g_param_spec_internal (G_TYPE_PARAM_OBJECT, name, nick, blurb, flags);
	G_PARAM_SPEC (spec)->value_type = object_type;
	return G_PARAM_SPEC (spec);
}


gpointer boxes_value_get_vm_creator (const GValue* value) {
	g_return_val_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, BOXES_TYPE_VM_CREATOR), NULL);
	return value->data[0].v_pointer;
}


void boxes_value_set_vm_creator (GValue* value, gpointer v_object) {
	BoxesVMCreator* old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, BOXES_TYPE_VM_CREATOR));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, BOXES_TYPE_VM_CREATOR));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
		boxes_vm_creator_ref (value->data[0].v_pointer);
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		boxes_vm_creator_unref (old);
	}
}


void boxes_value_take_vm_creator (GValue* value, gpointer v_object) {
	BoxesVMCreator* old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, BOXES_TYPE_VM_CREATOR));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, BOXES_TYPE_VM_CREATOR));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		boxes_vm_creator_unref (old);
	}
}


static void boxes_vm_creator_class_init (BoxesVMCreatorClass * klass) {
	boxes_vm_creator_parent_class = g_type_class_peek_parent (klass);
	BOXES_VM_CREATOR_CLASS (klass)->finalize = boxes_vm_creator_finalize;
	g_type_class_add_private (klass, sizeof (BoxesVMCreatorPrivate));
}


static void boxes_vm_creator_instance_init (BoxesVMCreator * self) {
	self->priv = BOXES_VM_CREATOR_GET_PRIVATE (self);
	self->ref_count = 1;
}


static void boxes_vm_creator_finalize (BoxesVMCreator* obj) {
	BoxesVMCreator * self;
	self = BOXES_VM_CREATOR (obj);
	_g_object_unref0 (self->priv->connection);
	_boxes_vm_configurator_unref0 (self->priv->configurator);
}


GType boxes_vm_creator_get_type (void) {
	static volatile gsize boxes_vm_creator_type_id__volatile = 0;
	if (g_once_init_enter (&boxes_vm_creator_type_id__volatile)) {
		static const GTypeValueTable g_define_type_value_table = { boxes_value_vm_creator_init, boxes_value_vm_creator_free_value, boxes_value_vm_creator_copy_value, boxes_value_vm_creator_peek_pointer, "p", boxes_value_vm_creator_collect_value, "p", boxes_value_vm_creator_lcopy_value };
		static const GTypeInfo g_define_type_info = { sizeof (BoxesVMCreatorClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) boxes_vm_creator_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (BoxesVMCreator), 0, (GInstanceInitFunc) boxes_vm_creator_instance_init, &g_define_type_value_table };
		static const GTypeFundamentalInfo g_define_type_fundamental_info = { (G_TYPE_FLAG_CLASSED | G_TYPE_FLAG_INSTANTIATABLE | G_TYPE_FLAG_DERIVABLE | G_TYPE_FLAG_DEEP_DERIVABLE) };
		GType boxes_vm_creator_type_id;
		boxes_vm_creator_type_id = g_type_register_fundamental (g_type_fundamental_next (), "BoxesVMCreator", &g_define_type_info, &g_define_type_fundamental_info, 0);
		g_once_init_leave (&boxes_vm_creator_type_id__volatile, boxes_vm_creator_type_id);
	}
	return boxes_vm_creator_type_id__volatile;
}


gpointer boxes_vm_creator_ref (gpointer instance) {
	BoxesVMCreator* self;
	self = instance;
	g_atomic_int_inc (&self->ref_count);
	return instance;
}


void boxes_vm_creator_unref (gpointer instance) {
	BoxesVMCreator* self;
	self = instance;
	if (g_atomic_int_dec_and_test (&self->ref_count)) {
		BOXES_VM_CREATOR_GET_CLASS (self)->finalize (self);
		g_type_free_instance ((GTypeInstance *) self);
	}
}



