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

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

#include <glib-object.h>
#include <glib.h>
#include <gio/gio.h>
#include <stdlib.h>
#include <string.h>
#include <libvirt-gconfig/libvirt-gconfig.h>
#include <libvirt-gobject/libvirt-gobject.h>
#include "common.h"
#include <osinfo/osinfo.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
#if !defined(VALA_EXTERN)
#if defined(_MSC_VER)
#define VALA_EXTERN __declspec(dllexport) extern
#elif __GNUC__ >= 4
#define VALA_EXTERN __attribute__((visibility("default"))) extern
#else
#define VALA_EXTERN extern
#endif
#endif

#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_COLLECTION_ITEM (boxes_collection_item_get_type ())
#define BOXES_COLLECTION_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), BOXES_TYPE_COLLECTION_ITEM, BoxesCollectionItem))
#define BOXES_COLLECTION_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), BOXES_TYPE_COLLECTION_ITEM, BoxesCollectionItemClass))
#define BOXES_IS_COLLECTION_ITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), BOXES_TYPE_COLLECTION_ITEM))
#define BOXES_IS_COLLECTION_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), BOXES_TYPE_COLLECTION_ITEM))
#define BOXES_COLLECTION_ITEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), BOXES_TYPE_COLLECTION_ITEM, BoxesCollectionItemClass))

typedef struct _BoxesCollectionItem BoxesCollectionItem;
typedef struct _BoxesCollectionItemClass BoxesCollectionItemClass;

#define BOXES_TYPE_MACHINE (boxes_machine_get_type ())
#define BOXES_MACHINE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), BOXES_TYPE_MACHINE, BoxesMachine))
#define BOXES_MACHINE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), BOXES_TYPE_MACHINE, BoxesMachineClass))
#define BOXES_IS_MACHINE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), BOXES_TYPE_MACHINE))
#define BOXES_IS_MACHINE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), BOXES_TYPE_MACHINE))
#define BOXES_MACHINE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), BOXES_TYPE_MACHINE, BoxesMachineClass))

typedef struct _BoxesMachine BoxesMachine;
typedef struct _BoxesMachineClass BoxesMachineClass;

#define BOXES_TYPE_LIBVIRT_MACHINE (boxes_libvirt_machine_get_type ())
#define BOXES_LIBVIRT_MACHINE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), BOXES_TYPE_LIBVIRT_MACHINE, BoxesLibvirtMachine))
#define BOXES_LIBVIRT_MACHINE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), BOXES_TYPE_LIBVIRT_MACHINE, BoxesLibvirtMachineClass))
#define BOXES_IS_LIBVIRT_MACHINE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), BOXES_TYPE_LIBVIRT_MACHINE))
#define BOXES_IS_LIBVIRT_MACHINE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), BOXES_TYPE_LIBVIRT_MACHINE))
#define BOXES_LIBVIRT_MACHINE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), BOXES_TYPE_LIBVIRT_MACHINE, BoxesLibvirtMachineClass))

typedef struct _BoxesLibvirtMachine BoxesLibvirtMachine;
typedef struct _BoxesLibvirtMachineClass BoxesLibvirtMachineClass;

#define BOXES_TYPE_VM_IMPORTER (boxes_vm_importer_get_type ())
#define BOXES_VM_IMPORTER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), BOXES_TYPE_VM_IMPORTER, BoxesVMImporter))
#define BOXES_VM_IMPORTER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), BOXES_TYPE_VM_IMPORTER, BoxesVMImporterClass))
#define BOXES_IS_VM_IMPORTER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), BOXES_TYPE_VM_IMPORTER))
#define BOXES_IS_VM_IMPORTER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), BOXES_TYPE_VM_IMPORTER))
#define BOXES_VM_IMPORTER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), BOXES_TYPE_VM_IMPORTER, BoxesVMImporterClass))

typedef struct _BoxesVMImporter BoxesVMImporter;
typedef struct _BoxesVMImporterClass BoxesVMImporterClass;
typedef struct _BoxesVMImporterPrivate BoxesVMImporterPrivate;

#define BOXES_TYPE_LIBVIRT_VM_IMPORTER (boxes_libvirt_vm_importer_get_type ())
#define BOXES_LIBVIRT_VM_IMPORTER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), BOXES_TYPE_LIBVIRT_VM_IMPORTER, BoxesLibvirtVMImporter))
#define BOXES_LIBVIRT_VM_IMPORTER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), BOXES_TYPE_LIBVIRT_VM_IMPORTER, BoxesLibvirtVMImporterClass))
#define BOXES_IS_LIBVIRT_VM_IMPORTER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), BOXES_TYPE_LIBVIRT_VM_IMPORTER))
#define BOXES_IS_LIBVIRT_VM_IMPORTER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), BOXES_TYPE_LIBVIRT_VM_IMPORTER))
#define BOXES_LIBVIRT_VM_IMPORTER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), BOXES_TYPE_LIBVIRT_VM_IMPORTER, BoxesLibvirtVMImporterClass))

typedef struct _BoxesLibvirtVMImporter BoxesLibvirtVMImporter;
typedef struct _BoxesLibvirtVMImporterClass BoxesLibvirtVMImporterClass;
typedef struct _BoxesLibvirtVMImporterPrivate BoxesLibvirtVMImporterPrivate;
enum  {
	BOXES_LIBVIRT_VM_IMPORTER_0_PROPERTY,
	BOXES_LIBVIRT_VM_IMPORTER_NUM_PROPERTIES
};
static GParamSpec* boxes_libvirt_vm_importer_properties[BOXES_LIBVIRT_VM_IMPORTER_NUM_PROPERTIES];

#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;

#define BOXES_TYPE_INSTALLED_MEDIA (boxes_installed_media_get_type ())
#define BOXES_INSTALLED_MEDIA(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), BOXES_TYPE_INSTALLED_MEDIA, BoxesInstalledMedia))
#define BOXES_INSTALLED_MEDIA_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), BOXES_TYPE_INSTALLED_MEDIA, BoxesInstalledMediaClass))
#define BOXES_IS_INSTALLED_MEDIA(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), BOXES_TYPE_INSTALLED_MEDIA))
#define BOXES_IS_INSTALLED_MEDIA_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), BOXES_TYPE_INSTALLED_MEDIA))
#define BOXES_INSTALLED_MEDIA_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), BOXES_TYPE_INSTALLED_MEDIA, BoxesInstalledMediaClass))

typedef struct _BoxesInstalledMedia BoxesInstalledMedia;
typedef struct _BoxesInstalledMediaClass BoxesInstalledMediaClass;

#define BOXES_TYPE_LIBVIRT_MEDIA (boxes_libvirt_media_get_type ())
#define BOXES_LIBVIRT_MEDIA(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), BOXES_TYPE_LIBVIRT_MEDIA, BoxesLibvirtMedia))
#define BOXES_LIBVIRT_MEDIA_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), BOXES_TYPE_LIBVIRT_MEDIA, BoxesLibvirtMediaClass))
#define BOXES_IS_LIBVIRT_MEDIA(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), BOXES_TYPE_LIBVIRT_MEDIA))
#define BOXES_IS_LIBVIRT_MEDIA_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), BOXES_TYPE_LIBVIRT_MEDIA))
#define BOXES_LIBVIRT_MEDIA_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), BOXES_TYPE_LIBVIRT_MEDIA, BoxesLibvirtMediaClass))

typedef struct _BoxesLibvirtMedia BoxesLibvirtMedia;
typedef struct _BoxesLibvirtMediaClass BoxesLibvirtMediaClass;
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef struct _BoxesInstallerMediaPrivate BoxesInstallerMediaPrivate;
typedef struct _BoxesLibvirtVmImporterCreateDomainConfigData BoxesLibvirtVmImporterCreateDomainConfigData;

struct _BoxesVMCreator {
	GObject parent_instance;
	BoxesVMCreatorPrivate * priv;
};

struct _BoxesVMCreatorClass {
	GObjectClass parent_class;
	void (*launch_vm) (BoxesVMCreator* self, BoxesLibvirtMachine* machine, gint64 access_last_time, gboolean clone, GError** error);
	void (*continue_installation) (BoxesVMCreator* self, BoxesLibvirtMachine* machine, GAsyncReadyCallback _callback_, gpointer _user_data_);
	void (*continue_installation_finish) (BoxesVMCreator* self, GAsyncResult* _res_);
	void (*create_domain_config) (BoxesVMCreator* self, const gchar* name, const gchar* title, const gchar* volume_path, GCancellable* cancellable, GAsyncReadyCallback _callback_, gpointer _user_data_);
	GVirConfigDomain* (*create_domain_config_finish) (BoxesVMCreator* self, GAsyncResult* _res_, GError** error);
	void (*create_domain_base_name_and_title) (BoxesVMCreator* self, gchar** base_name, gchar** base_title);
};

struct _BoxesVMImporter {
	BoxesVMCreator parent_instance;
	BoxesVMImporterPrivate * priv;
	gboolean start_after_import;
};

struct _BoxesVMImporterClass {
	BoxesVMCreatorClass parent_class;
	void (*post_import_setup) (BoxesVMImporter* self, BoxesLibvirtMachine* machine, GAsyncReadyCallback _callback_, gpointer _user_data_);
	void (*post_import_setup_finish) (BoxesVMImporter* self, GAsyncResult* _res_);
};

struct _BoxesLibvirtVMImporter {
	BoxesVMImporter parent_instance;
	BoxesLibvirtVMImporterPrivate * priv;
};

struct _BoxesLibvirtVMImporterClass {
	BoxesVMImporterClass parent_class;
};

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

struct _BoxesInstallerMediaClass {
	GObjectClass parent_class;
	void (*set_direct_boot_params) (BoxesInstallerMedia* self, GVirConfigDomainOs* os);
	void (*prepare) (BoxesInstallerMedia* self, BoxesActivityProgress* progress, GCancellable* cancellable, GAsyncReadyCallback _callback_, gpointer _user_data_);
	gboolean (*prepare_finish) (BoxesInstallerMedia* self, GAsyncResult* _res_);
	void (*prepare_for_installation) (BoxesInstallerMedia* self, const gchar* vm_name, GCancellable* cancellable, GAsyncReadyCallback _callback_, gpointer _user_data_);
	void (*prepare_for_installation_finish) (BoxesInstallerMedia* self, GAsyncResult* _res_);
	void (*prepare_to_continue_installation) (BoxesInstallerMedia* self, const gchar* vm_name);
	void (*clean_up) (BoxesInstallerMedia* self);
	void (*clean_up_preparation_cache) (BoxesInstallerMedia* self);
	void (*setup_domain_config) (BoxesInstallerMedia* self, GVirConfigDomain* domain);
	void (*setup_post_install_domain_config) (BoxesInstallerMedia* self, GVirConfigDomain* domain);
	BoxesVMCreator* (*get_vm_creator) (BoxesInstallerMedia* self);
	OsinfoDeviceList* (*get_supported_devices) (BoxesInstallerMedia* self);
	guint64 (*get_installed_size) (BoxesInstallerMedia* self);
	gboolean (*get_need_user_input_for_vm_creation) (BoxesInstallerMedia* self);
	gboolean (*get_prefers_q35) (BoxesInstallerMedia* self);
	gboolean (*get_prefers_ich9) (BoxesInstallerMedia* self);
	gboolean (*get_live) (BoxesInstallerMedia* self);
	gboolean (*get_eject_after_install) (BoxesInstallerMedia* self);
	gchar* (*get_architecture) (BoxesInstallerMedia* self);
};

struct _BoxesLibvirtVmImporterCreateDomainConfigData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	BoxesLibvirtVMImporter* self;
	gchar* name;
	gchar* title;
	gchar* volume_path;
	GCancellable* cancellable;
	GVirConfigDomain* result;
	BoxesLibvirtMedia* media;
	BoxesInstallerMedia* _tmp0_;
	BoxesInstallerMedia* _tmp1_;
	BoxesLibvirtMedia* _tmp2_;
	GVirConfigDomain* config;
	BoxesLibvirtMedia* _tmp3_;
	GVirConfigDomain* _tmp4_;
	GVirConfigDomain* _tmp5_;
	GVirConfigDomain* _tmp6_;
	GVirConfigDomain* _tmp7_;
	GVirConfigDomain* _tmp8_;
	GVirConfigDomain* _tmp9_;
	BoxesInstallerMedia* _tmp10_;
	BoxesInstallerMedia* _tmp11_;
	GVirConfigDomain* _tmp12_;
	GVirConnection* _tmp13_;
	GVirConnection* _tmp14_;
	GVirConnection* _tmp15_;
	GList* devices;
	GVirConfigDomain* _tmp16_;
	GList* _tmp17_;
	GList* filtered;
	gint hd_index;
	GList* _tmp18_;
	GList* device_collection;
	GList* device_it;
	GVirConfigDomainDevice* _tmp19_;
	GVirConfigDomainDevice* device;
	GVirConfigDomainDevice* _tmp20_;
	GVirConfigDomainDisk* disk;
	GVirConfigDomainDevice* _tmp21_;
	GVirConfigDomainDisk* _tmp22_;
	GVirConfigDomainDisk* _tmp23_;
	const gchar* _tmp24_;
	BoxesLibvirtMedia* _tmp25_;
	const gchar* _tmp26_;
	GVirConfigDomainDisk* _tmp27_;
	gchar* dev;
	GVirConfigDomainDisk* _tmp28_;
	const gchar* _tmp29_;
	gchar* _tmp30_;
	gint cd_index;
	const gchar* _tmp31_;
	const gchar* _tmp32_;
	gint _tmp33_;
	gint _tmp34_;
	gint _tmp35_;
	GVirConfigDomainDevice* _tmp36_;
	GVirConfigDomainDevice* _tmp37_;
	GVirConfigDomain* _tmp38_;
	GList* _tmp39_;
	GVirConfigDomain* _tmp40_;
	BoxesInstallerMedia* _tmp41_;
	BoxesInstallerMedia* _tmp42_;
};

static gpointer boxes_libvirt_vm_importer_parent_class = NULL;

VALA_EXTERN GType boxes_vm_creator_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (BoxesVMCreator, g_object_unref)
VALA_EXTERN GType boxes_collection_item_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (BoxesCollectionItem, g_object_unref)
VALA_EXTERN GType boxes_machine_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (BoxesMachine, g_object_unref)
VALA_EXTERN GType boxes_libvirt_machine_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (BoxesLibvirtMachine, g_object_unref)
VALA_EXTERN GType boxes_vm_importer_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (BoxesVMImporter, g_object_unref)
VALA_EXTERN GType boxes_libvirt_vm_importer_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (BoxesLibvirtVMImporter, g_object_unref)
VALA_EXTERN void boxes_vm_creator_create_domain_base_name_and_title (BoxesVMCreator* self,
                                                         gchar** base_name,
                                                         gchar** base_title);
VALA_EXTERN void boxes_vm_creator_create_domain_config (BoxesVMCreator* self,
                                            const gchar* name,
                                            const gchar* title,
                                            const gchar* volume_path,
                                            GCancellable* cancellable,
                                            GAsyncReadyCallback _callback_,
                                            gpointer _user_data_);
VALA_EXTERN GVirConfigDomain* boxes_vm_creator_create_domain_config_finish (BoxesVMCreator* self,
                                                                GAsyncResult* _res_,
                                                                GError** error);
VALA_EXTERN GType boxes_installer_media_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (BoxesInstallerMedia, g_object_unref)
VALA_EXTERN GType boxes_installed_media_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (BoxesInstalledMedia, g_object_unref)
VALA_EXTERN BoxesLibvirtVMImporter* boxes_libvirt_vm_importer_new (BoxesInstalledMedia* source_media);
VALA_EXTERN BoxesLibvirtVMImporter* boxes_libvirt_vm_importer_construct (GType object_type,
                                                             BoxesInstalledMedia* source_media);
VALA_EXTERN BoxesVMImporter* boxes_vm_importer_new (BoxesInstalledMedia* source_media);
VALA_EXTERN BoxesVMImporter* boxes_vm_importer_construct (GType object_type,
                                              BoxesInstalledMedia* source_media);
VALA_EXTERN BoxesLibvirtVMImporter* boxes_libvirt_vm_importer_new_for_import_completion (BoxesLibvirtMachine* machine);
VALA_EXTERN BoxesLibvirtVMImporter* boxes_libvirt_vm_importer_construct_for_import_completion (GType object_type,
                                                                                   BoxesLibvirtMachine* machine);
VALA_EXTERN BoxesVMCreator* boxes_vm_creator_new_for_install_completion (BoxesLibvirtMachine* machine);
VALA_EXTERN BoxesVMCreator* boxes_vm_creator_construct_for_install_completion (GType object_type,
                                                                   BoxesLibvirtMachine* machine);
static void boxes_libvirt_vm_importer_real_create_domain_base_name_and_title (BoxesVMCreator* base,
                                                                       gchar** base_name,
                                                                       gchar** base_title);
VALA_EXTERN GType boxes_libvirt_media_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (BoxesLibvirtMedia, g_object_unref)
VALA_EXTERN BoxesInstallerMedia* boxes_vm_creator_get_install_media (BoxesVMCreator* self);
VALA_EXTERN GVirConfigDomain* boxes_libvirt_media_get_domain_config (BoxesLibvirtMedia* self);
static void boxes_libvirt_vm_importer_real_create_domain_config_data_free (gpointer _data);
static void boxes_libvirt_vm_importer_real_create_domain_config (BoxesVMCreator* base,
                                                          const gchar* name,
                                                          const gchar* title,
                                                          const gchar* volume_path,
                                                          GCancellable* cancellable,
                                                          GAsyncReadyCallback _callback_,
                                                          gpointer _user_data_);
static gboolean boxes_libvirt_vm_importer_real_create_domain_config_co (BoxesLibvirtVmImporterCreateDomainConfigData* _data_);
VALA_EXTERN void boxes_vm_configurator_setup_custom_xml (GVirConfigDomain* domain,
                                             BoxesInstallerMedia* install_media);
VALA_EXTERN void boxes_vm_configurator_update_existing_domain (GVirConfigDomain* domain,
                                                   GVirConnection* connection,
                                                   GAsyncReadyCallback _callback_,
                                                   gpointer _user_data_);
VALA_EXTERN void boxes_vm_configurator_update_existing_domain_finish (GAsyncResult* _res_);
VALA_EXTERN GVirConnection* boxes_vm_creator_get_connection (BoxesVMCreator* self);
static void boxes_libvirt_vm_importer_create_domain_config_ready (GObject* source_object,
                                                           GAsyncResult* _res_,
                                                           gpointer _user_data_);
VALA_EXTERN void boxes_vm_configurator_set_target_media_config (GVirConfigDomain* domain,
                                                    const gchar* target_path,
                                                    BoxesInstallerMedia* install_media,
                                                    guint8 dev_index);
static void _g_object_unref0_ (gpointer var);
static inline void _g_list_free__g_object_unref0_ (GList* self);
static GType boxes_libvirt_vm_importer_get_type_once (void);

BoxesLibvirtVMImporter*
boxes_libvirt_vm_importer_construct (GType object_type,
                                     BoxesInstalledMedia* source_media)
{
	BoxesLibvirtVMImporter * self = NULL;
	g_return_val_if_fail (source_media != NULL, NULL);
	self = (BoxesLibvirtVMImporter*) boxes_vm_importer_construct (object_type, source_media);
	((BoxesVMImporter*) self)->start_after_import = FALSE;
	return self;
}

BoxesLibvirtVMImporter*
boxes_libvirt_vm_importer_new (BoxesInstalledMedia* source_media)
{
	return boxes_libvirt_vm_importer_construct (BOXES_TYPE_LIBVIRT_VM_IMPORTER, source_media);
}

BoxesLibvirtVMImporter*
boxes_libvirt_vm_importer_construct_for_import_completion (GType object_type,
                                                           BoxesLibvirtMachine* machine)
{
	BoxesLibvirtVMImporter * self = NULL;
	g_return_val_if_fail (machine != NULL, NULL);
	self = (BoxesLibvirtVMImporter*) boxes_vm_creator_construct_for_install_completion (object_type, machine);
	((BoxesVMImporter*) self)->start_after_import = FALSE;
	return self;
}

BoxesLibvirtVMImporter*
boxes_libvirt_vm_importer_new_for_import_completion (BoxesLibvirtMachine* machine)
{
	return boxes_libvirt_vm_importer_construct_for_import_completion (BOXES_TYPE_LIBVIRT_VM_IMPORTER, machine);
}

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

static void
boxes_libvirt_vm_importer_real_create_domain_base_name_and_title (BoxesVMCreator* base,
                                                                  gchar** base_name,
                                                                  gchar** base_title)
{
	BoxesLibvirtVMImporter * self;
	gchar* _vala_base_name = NULL;
	gchar* _vala_base_title = NULL;
	BoxesLibvirtMedia* media = NULL;
	BoxesInstallerMedia* _tmp0_;
	BoxesInstallerMedia* _tmp1_;
	BoxesLibvirtMedia* _tmp2_;
	BoxesLibvirtMedia* _tmp3_;
	GVirConfigDomain* _tmp4_;
	GVirConfigDomain* _tmp5_;
	const gchar* _tmp6_;
	const gchar* _tmp7_;
	gchar* _tmp8_;
	const gchar* _tmp9_ = NULL;
	BoxesLibvirtMedia* _tmp10_;
	GVirConfigDomain* _tmp11_;
	GVirConfigDomain* _tmp12_;
	const gchar* _tmp13_;
	const gchar* _tmp14_;
	gchar* _tmp16_;
	self = (BoxesLibvirtVMImporter*) base;
	_tmp0_ = boxes_vm_creator_get_install_media ((BoxesVMCreator*) self);
	_tmp1_ = _tmp0_;
	_tmp2_ = _g_object_ref0 (BOXES_IS_LIBVIRT_MEDIA (_tmp1_) ? ((BoxesLibvirtMedia*) _tmp1_) : NULL);
	media = _tmp2_;
	_tmp3_ = media;
	_tmp4_ = boxes_libvirt_media_get_domain_config (_tmp3_);
	_tmp5_ = _tmp4_;
	_tmp6_ = gvir_config_domain_get_name (_tmp5_);
	_tmp7_ = _tmp6_;
	_tmp8_ = g_strdup (_tmp7_);
	_g_free0 (_vala_base_name);
	_vala_base_name = _tmp8_;
	_tmp10_ = media;
	_tmp11_ = boxes_libvirt_media_get_domain_config (_tmp10_);
	_tmp12_ = _tmp11_;
	_tmp13_ = gvir_config_domain_get_title (_tmp12_);
	_tmp14_ = _tmp13_;
	_tmp9_ = _tmp14_;
	if (_tmp9_ == NULL) {
		const gchar* _tmp15_;
		_tmp15_ = _vala_base_name;
		_tmp9_ = _tmp15_;
	}
	_tmp16_ = g_strdup (_tmp9_);
	_g_free0 (_vala_base_title);
	_vala_base_title = _tmp16_;
	_g_object_unref0 (media);
	if (base_name) {
		*base_name = _vala_base_name;
	} else {
		_g_free0 (_vala_base_name);
	}
	if (base_title) {
		*base_title = _vala_base_title;
	} else {
		_g_free0 (_vala_base_title);
	}
}

static void
boxes_libvirt_vm_importer_real_create_domain_config_data_free (gpointer _data)
{
	BoxesLibvirtVmImporterCreateDomainConfigData* _data_;
	_data_ = _data;
	_g_free0 (_data_->name);
	_g_free0 (_data_->title);
	_g_free0 (_data_->volume_path);
	_g_object_unref0 (_data_->cancellable);
	_g_object_unref0 (_data_->result);
	_g_object_unref0 (_data_->self);
	g_slice_free (BoxesLibvirtVmImporterCreateDomainConfigData, _data_);
}

static void
boxes_libvirt_vm_importer_real_create_domain_config (BoxesVMCreator* base,
                                                     const gchar* name,
                                                     const gchar* title,
                                                     const gchar* volume_path,
                                                     GCancellable* cancellable,
                                                     GAsyncReadyCallback _callback_,
                                                     gpointer _user_data_)
{
	BoxesLibvirtVMImporter * self;
	BoxesLibvirtVmImporterCreateDomainConfigData* _data_;
	BoxesLibvirtVMImporter* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	GCancellable* _tmp4_;
	g_return_if_fail (name != NULL);
	g_return_if_fail (title != NULL);
	g_return_if_fail (volume_path != NULL);
	self = (BoxesLibvirtVMImporter*) base;
	_data_ = g_slice_new0 (BoxesLibvirtVmImporterCreateDomainConfigData);
	_data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, boxes_libvirt_vm_importer_real_create_domain_config_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = g_strdup (name);
	_g_free0 (_data_->name);
	_data_->name = _tmp1_;
	_tmp2_ = g_strdup (title);
	_g_free0 (_data_->title);
	_data_->title = _tmp2_;
	_tmp3_ = g_strdup (volume_path);
	_g_free0 (_data_->volume_path);
	_data_->volume_path = _tmp3_;
	_tmp4_ = _g_object_ref0 (cancellable);
	_g_object_unref0 (_data_->cancellable);
	_data_->cancellable = _tmp4_;
	boxes_libvirt_vm_importer_real_create_domain_config_co (_data_);
}

static GVirConfigDomain*
boxes_libvirt_vm_importer_create_domain_config_finish (BoxesVMCreator* base,
                                                       GAsyncResult* _res_,
                                                       GError** error)
{
	GVirConfigDomain* result;
	BoxesLibvirtVmImporterCreateDomainConfigData* _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
boxes_libvirt_vm_importer_create_domain_config_ready (GObject* source_object,
                                                      GAsyncResult* _res_,
                                                      gpointer _user_data_)
{
	BoxesLibvirtVmImporterCreateDomainConfigData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	boxes_libvirt_vm_importer_real_create_domain_config_co (_data_);
}

static gchar
string_get (const gchar* self,
            glong index)
{
	gchar _tmp0_;
	gchar result;
	g_return_val_if_fail (self != NULL, '\0');
	_tmp0_ = ((gchar*) self)[index];
	result = _tmp0_;
	return result;
}

static void
_g_object_unref0_ (gpointer var)
{
	(var == NULL) ? NULL : (var = (g_object_unref (var), NULL));
}

static inline void
_g_list_free__g_object_unref0_ (GList* self)
{
	g_list_free_full (self, (GDestroyNotify) _g_object_unref0_);
}

static gboolean
boxes_libvirt_vm_importer_real_create_domain_config_co (BoxesLibvirtVmImporterCreateDomainConfigData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = boxes_vm_creator_get_install_media ((BoxesVMCreator*) _data_->self);
	_data_->_tmp1_ = _data_->_tmp0_;
	_data_->_tmp2_ = _g_object_ref0 (BOXES_IS_LIBVIRT_MEDIA (_data_->_tmp1_) ? ((BoxesLibvirtMedia*) _data_->_tmp1_) : NULL);
	_data_->media = _data_->_tmp2_;
	_data_->_tmp3_ = _data_->media;
	_data_->_tmp4_ = boxes_libvirt_media_get_domain_config (_data_->_tmp3_);
	_data_->_tmp5_ = _data_->_tmp4_;
	_data_->_tmp6_ = _g_object_ref0 (_data_->_tmp5_);
	_data_->config = _data_->_tmp6_;
	_data_->_tmp7_ = _data_->config;
	gvir_config_domain_set_name (_data_->_tmp7_, _data_->name);
	_data_->_tmp8_ = _data_->config;
	gvir_config_domain_set_title (_data_->_tmp8_, _data_->title);
	_data_->_tmp9_ = _data_->config;
	_data_->_tmp10_ = boxes_vm_creator_get_install_media ((BoxesVMCreator*) _data_->self);
	_data_->_tmp11_ = _data_->_tmp10_;
	boxes_vm_configurator_setup_custom_xml (_data_->_tmp9_, _data_->_tmp11_);
	_data_->_tmp12_ = _data_->config;
	_data_->_tmp13_ = boxes_vm_creator_get_connection ((BoxesVMCreator*) _data_->self);
	_data_->_tmp14_ = _data_->_tmp13_;
	_data_->_tmp15_ = _data_->_tmp14_;
	_data_->_state_ = 1;
	boxes_vm_configurator_update_existing_domain (_data_->_tmp12_, _data_->_tmp15_, boxes_libvirt_vm_importer_create_domain_config_ready, _data_);
	return FALSE;
	_state_1:
	boxes_vm_configurator_update_existing_domain_finish (_data_->_res_);
	_g_object_unref0 (_data_->_tmp15_);
	_data_->_tmp16_ = _data_->config;
	_data_->_tmp17_ = gvir_config_domain_get_devices (_data_->_tmp16_);
	_data_->devices = _data_->_tmp17_;
	_data_->filtered = NULL;
	_data_->hd_index = 0;
	_data_->_tmp18_ = _data_->devices;
	{
		_data_->device_collection = _data_->_tmp18_;
		for (_data_->device_it = _data_->device_collection; _data_->device_it != NULL; _data_->device_it = _data_->device_it->next) {
			_data_->_tmp19_ = _g_object_ref0 ((GVirConfigDomainDevice*) _data_->device_it->data);
			_data_->device = _data_->_tmp19_;
			{
				_data_->_tmp20_ = _data_->device;
				if (G_TYPE_CHECK_INSTANCE_TYPE (_data_->_tmp20_, gvir_config_domain_disk_get_type ())) {
					_data_->_tmp21_ = _data_->device;
					_data_->_tmp22_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_data_->_tmp21_, gvir_config_domain_disk_get_type ()) ? ((GVirConfigDomainDisk*) _data_->_tmp21_) : NULL);
					_data_->disk = _data_->_tmp22_;
					_data_->_tmp23_ = _data_->disk;
					_data_->_tmp24_ = gvir_config_domain_disk_get_source (_data_->_tmp23_);
					_data_->_tmp25_ = _data_->media;
					_data_->_tmp26_ = ((BoxesInstallerMedia*) _data_->_tmp25_)->device_file;
					if (g_strcmp0 (_data_->_tmp24_, _data_->_tmp26_) == 0) {
						_g_object_unref0 (_data_->disk);
						_g_object_unref0 (_data_->device);
						continue;
					}
					_data_->_tmp27_ = _data_->disk;
					if (gvir_config_domain_disk_get_guest_device_type (_data_->_tmp27_) == GVIR_CONFIG_DOMAIN_DISK_GUEST_DEVICE_CDROM) {
						_data_->_tmp28_ = _data_->disk;
						_data_->_tmp29_ = gvir_config_domain_disk_get_target_dev (_data_->_tmp28_);
						_data_->_tmp30_ = g_strdup (_data_->_tmp29_);
						_data_->dev = _data_->_tmp30_;
						_data_->_tmp31_ = _data_->dev;
						_data_->_tmp32_ = _data_->dev;
						_data_->_tmp33_ = strlen (_data_->_tmp32_);
						_data_->_tmp34_ = _data_->_tmp33_;
						_data_->cd_index = ((guint8) string_get (_data_->_tmp31_, (glong) (_data_->_tmp34_ - 1))) - 97;
						if (_data_->cd_index != 0) {
							_data_->_tmp35_ = 0;
						} else {
							_data_->_tmp35_ = _data_->cd_index + 1;
						}
						_data_->hd_index = _data_->_tmp35_;
						_g_free0 (_data_->dev);
					}
					_g_object_unref0 (_data_->disk);
				}
				_data_->_tmp36_ = _data_->device;
				_data_->_tmp37_ = _g_object_ref0 (_data_->_tmp36_);
				_data_->filtered = g_list_prepend (_data_->filtered, _data_->_tmp37_);
				_g_object_unref0 (_data_->device);
			}
		}
	}
	_data_->filtered = g_list_reverse (_data_->filtered);
	_data_->_tmp38_ = _data_->config;
	_data_->_tmp39_ = _data_->filtered;
	gvir_config_domain_set_devices (_data_->_tmp38_, _data_->_tmp39_);
	_data_->_tmp40_ = _data_->config;
	_data_->_tmp41_ = boxes_vm_creator_get_install_media ((BoxesVMCreator*) _data_->self);
	_data_->_tmp42_ = _data_->_tmp41_;
	boxes_vm_configurator_set_target_media_config (_data_->_tmp40_, _data_->volume_path, _data_->_tmp42_, (guint8) _data_->hd_index);
	_data_->result = _data_->config;
	(_data_->filtered == NULL) ? NULL : (_data_->filtered = (_g_list_free__g_object_unref0_ (_data_->filtered), NULL));
	(_data_->devices == NULL) ? NULL : (_data_->devices = (_g_list_free__g_object_unref0_ (_data_->devices), NULL));
	_g_object_unref0 (_data_->media);
	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
boxes_libvirt_vm_importer_class_init (BoxesLibvirtVMImporterClass * klass,
                                      gpointer klass_data)
{
	boxes_libvirt_vm_importer_parent_class = g_type_class_peek_parent (klass);
	((BoxesVMCreatorClass *) klass)->create_domain_base_name_and_title = (void (*) (BoxesVMCreator*, gchar**, gchar**)) boxes_libvirt_vm_importer_real_create_domain_base_name_and_title;
	((BoxesVMCreatorClass *) klass)->create_domain_config = (void (*) (BoxesVMCreator*, const gchar*, const gchar*, const gchar*, GCancellable*, GAsyncReadyCallback, gpointer)) boxes_libvirt_vm_importer_real_create_domain_config;
	((BoxesVMCreatorClass *) klass)->create_domain_config_finish = (GVirConfigDomain* (*) (BoxesVMCreator*, GAsyncResult*, GError**)) boxes_libvirt_vm_importer_create_domain_config_finish;
}

static void
boxes_libvirt_vm_importer_instance_init (BoxesLibvirtVMImporter * self,
                                         gpointer klass)
{
}

static GType
boxes_libvirt_vm_importer_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (BoxesLibvirtVMImporterClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) boxes_libvirt_vm_importer_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (BoxesLibvirtVMImporter), 0, (GInstanceInitFunc) boxes_libvirt_vm_importer_instance_init, NULL };
	GType boxes_libvirt_vm_importer_type_id;
	boxes_libvirt_vm_importer_type_id = g_type_register_static (BOXES_TYPE_VM_IMPORTER, "BoxesLibvirtVMImporter", &g_define_type_info, 0);
	return boxes_libvirt_vm_importer_type_id;
}

GType
boxes_libvirt_vm_importer_get_type (void)
{
	static volatile gsize boxes_libvirt_vm_importer_type_id__once = 0;
	if (g_once_init_enter (&boxes_libvirt_vm_importer_type_id__once)) {
		GType boxes_libvirt_vm_importer_type_id;
		boxes_libvirt_vm_importer_type_id = boxes_libvirt_vm_importer_get_type_once ();
		g_once_init_leave (&boxes_libvirt_vm_importer_type_id__once, boxes_libvirt_vm_importer_type_id);
	}
	return boxes_libvirt_vm_importer_type_id__once;
}

