ApplianceImpl.h revision 6b9316bfe743cc7d2ee00d925f4ab455bc224e86
f9fc8c7343143818644af6caf51a2b2520b8b7a9vboxsync/* $Id$ */
50e5e7a2b25a463c312cf741832fcc34d36557bdvboxsync
15617cf4cb5fa181f4d6f55f987a883cf298cce6vboxsync/** @file
f9fc8c7343143818644af6caf51a2b2520b8b7a9vboxsync *
50e5e7a2b25a463c312cf741832fcc34d36557bdvboxsync * VirtualBox COM class implementation
50e5e7a2b25a463c312cf741832fcc34d36557bdvboxsync */
50e5e7a2b25a463c312cf741832fcc34d36557bdvboxsync
f9fc8c7343143818644af6caf51a2b2520b8b7a9vboxsync/*
f9fc8c7343143818644af6caf51a2b2520b8b7a9vboxsync * Copyright (C) 2006-2009 Sun Microsystems, Inc.
f9fc8c7343143818644af6caf51a2b2520b8b7a9vboxsync *
f9fc8c7343143818644af6caf51a2b2520b8b7a9vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
f9fc8c7343143818644af6caf51a2b2520b8b7a9vboxsync * available from http://www.virtualbox.org. This file is free software;
f9fc8c7343143818644af6caf51a2b2520b8b7a9vboxsync * you can redistribute it and/or modify it under the terms of the GNU
f9fc8c7343143818644af6caf51a2b2520b8b7a9vboxsync * General Public License (GPL) as published by the Free Software
f9fc8c7343143818644af6caf51a2b2520b8b7a9vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
f9fc8c7343143818644af6caf51a2b2520b8b7a9vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
f9fc8c7343143818644af6caf51a2b2520b8b7a9vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
546cd3313d635980a2cc168a79a58b4f0858d784vboxsync *
546cd3313d635980a2cc168a79a58b4f0858d784vboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
546cd3313d635980a2cc168a79a58b4f0858d784vboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
546cd3313d635980a2cc168a79a58b4f0858d784vboxsync * additional information or have any questions.
546cd3313d635980a2cc168a79a58b4f0858d784vboxsync */
546cd3313d635980a2cc168a79a58b4f0858d784vboxsync
15617cf4cb5fa181f4d6f55f987a883cf298cce6vboxsync#ifndef ____H_APPLIANCEIMPL
15617cf4cb5fa181f4d6f55f987a883cf298cce6vboxsync#define ____H_APPLIANCEIMPL
f9fc8c7343143818644af6caf51a2b2520b8b7a9vboxsync
15617cf4cb5fa181f4d6f55f987a883cf298cce6vboxsync/* VBox includes */
15617cf4cb5fa181f4d6f55f987a883cf298cce6vboxsync#include "VirtualBoxBase.h"
15617cf4cb5fa181f4d6f55f987a883cf298cce6vboxsync
15617cf4cb5fa181f4d6f55f987a883cf298cce6vboxsync#include "ovfreader.h"
15617cf4cb5fa181f4d6f55f987a883cf298cce6vboxsync
15617cf4cb5fa181f4d6f55f987a883cf298cce6vboxsync/* VBox forward declarations */
15617cf4cb5fa181f4d6f55f987a883cf298cce6vboxsyncclass Progress;
15617cf4cb5fa181f4d6f55f987a883cf298cce6vboxsyncclass VirtualSystemDescription;
15617cf4cb5fa181f4d6f55f987a883cf298cce6vboxsync
15617cf4cb5fa181f4d6f55f987a883cf298cce6vboxsyncclass ATL_NO_VTABLE Appliance :
15617cf4cb5fa181f4d6f55f987a883cf298cce6vboxsync public VirtualBoxBase,
15617cf4cb5fa181f4d6f55f987a883cf298cce6vboxsync public VirtualBoxSupportErrorInfoImpl<Appliance, IAppliance>,
15617cf4cb5fa181f4d6f55f987a883cf298cce6vboxsync public VirtualBoxSupportTranslation<Appliance>,
15617cf4cb5fa181f4d6f55f987a883cf298cce6vboxsync VBOX_SCRIPTABLE_IMPL(IAppliance)
15617cf4cb5fa181f4d6f55f987a883cf298cce6vboxsync{
395d92a7732aad3c0b9baecedfabba5113b84485vboxsyncpublic:
395d92a7732aad3c0b9baecedfabba5113b84485vboxsync VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT (Appliance)
395d92a7732aad3c0b9baecedfabba5113b84485vboxsync
50e5e7a2b25a463c312cf741832fcc34d36557bdvboxsync DECLARE_NOT_AGGREGATABLE(Appliance)
50e5e7a2b25a463c312cf741832fcc34d36557bdvboxsync
50e5e7a2b25a463c312cf741832fcc34d36557bdvboxsync DECLARE_PROTECT_FINAL_CONSTRUCT()
15617cf4cb5fa181f4d6f55f987a883cf298cce6vboxsync
15617cf4cb5fa181f4d6f55f987a883cf298cce6vboxsync BEGIN_COM_MAP(Appliance)
15617cf4cb5fa181f4d6f55f987a883cf298cce6vboxsync COM_INTERFACE_ENTRY(ISupportErrorInfo)
15617cf4cb5fa181f4d6f55f987a883cf298cce6vboxsync COM_INTERFACE_ENTRY(IAppliance)
15617cf4cb5fa181f4d6f55f987a883cf298cce6vboxsync COM_INTERFACE_ENTRY(IDispatch)
15617cf4cb5fa181f4d6f55f987a883cf298cce6vboxsync END_COM_MAP()
a3f342a86f026f46fed32aae20ca045db066d141vboxsync
a3f342a86f026f46fed32aae20ca045db066d141vboxsync DECLARE_EMPTY_CTOR_DTOR (Appliance)
a3f342a86f026f46fed32aae20ca045db066d141vboxsync
15617cf4cb5fa181f4d6f55f987a883cf298cce6vboxsync enum OVFFormat
15617cf4cb5fa181f4d6f55f987a883cf298cce6vboxsync {
15617cf4cb5fa181f4d6f55f987a883cf298cce6vboxsync unspecified,
15617cf4cb5fa181f4d6f55f987a883cf298cce6vboxsync OVF_0_9,
f9fc8c7343143818644af6caf51a2b2520b8b7a9vboxsync OVF_1_0
15617cf4cb5fa181f4d6f55f987a883cf298cce6vboxsync };
a3f342a86f026f46fed32aae20ca045db066d141vboxsync
// public initializer/uninitializer for internal purposes only
HRESULT FinalConstruct() { return S_OK; }
void FinalRelease() { uninit(); }
HRESULT init(VirtualBox *aVirtualBox);
void uninit();
// for VirtualBoxSupportErrorInfoImpl
static const wchar_t *getComponentName() { return L"Appliance"; }
/* IAppliance properties */
STDMETHOD(COMGETTER(Path))(BSTR *aPath);
STDMETHOD(COMGETTER(Disks))(ComSafeArrayOut(BSTR, aDisks));
STDMETHOD(COMGETTER(VirtualSystemDescriptions))(ComSafeArrayOut(IVirtualSystemDescription*, aVirtualSystemDescriptions));
/* IAppliance methods */
/* Import methods */
STDMETHOD(Read)(IN_BSTR path, IProgress **aProgress);
STDMETHOD(Interpret)(void);
STDMETHOD(ImportMachines)(IProgress **aProgress);
/* Export methods */
STDMETHOD(CreateVFSExplorer)(IN_BSTR aURI, IVFSExplorer **aExplorer);
STDMETHOD(Write)(IN_BSTR format, IN_BSTR path, IProgress **aProgress);
STDMETHOD(GetWarnings)(ComSafeArrayOut(BSTR, aWarnings));
/* public methods only for internal purposes */
/* private instance data */
private:
/** weak VirtualBox parent */
VirtualBox* const mVirtualBox;
struct Data; // opaque, defined in ApplianceImpl.cpp
Data *m;
bool isApplianceIdle() const;
HRESULT searchUniqueVMName(Utf8Str& aName) const;
HRESULT searchUniqueDiskImageFilePath(Utf8Str& aName) const;
void waitForAsyncProgress(ComObjPtr<Progress> &pProgressThis, ComPtr<IProgress> &pProgressAsync);
void addWarning(const char* aWarning, ...);
void disksWeight(uint32_t &ulTotalMB, uint32_t &cDisks) const;
HRESULT setUpProgressFS(ComObjPtr<Progress> &pProgress, const Bstr &bstrDescription);
HRESULT setUpProgressImportS3(ComObjPtr<Progress> &pProgress, const Bstr &bstrDescription);
HRESULT setUpProgressWriteS3(ComObjPtr<Progress> &pProgress, const Bstr &bstrDescription);
struct LocationInfo;
void parseURI(Utf8Str strUri, LocationInfo &locInfo) const;
void parseBucket(Utf8Str &aPath, Utf8Str &aBucket) const;
Utf8Str manifestFileName(Utf8Str aPath) const;
HRESULT readImpl(const LocationInfo &aLocInfo, ComObjPtr<Progress> &aProgress);
struct TaskOVF;
static DECLCALLBACK(int) taskThreadImportOrExport(RTTHREAD aThread, void *pvUser);
HRESULT readFS(const LocationInfo &locInfo);
HRESULT readS3(TaskOVF *pTask);
void convertDiskAttachmentValues(const HardDiskController &hdc,
uint32_t ulAddressOnParent,
Bstr &controllerType,
int32_t &lChannel,
int32_t &lDevice);
HRESULT importImpl(const LocationInfo &aLocInfo, ComObjPtr<Progress> &aProgress);
HRESULT importFS(const LocationInfo &locInfo, ComObjPtr<Progress> &aProgress);
HRESULT importS3(TaskOVF *pTask);
HRESULT writeImpl(OVFFormat aFormat, const LocationInfo &aLocInfo, ComObjPtr<Progress> &aProgress);
struct XMLStack;
void buildXMLForOneVirtualSystem(xml::ElementNode &elmToAddVirtualSystemsTo,
ComObjPtr<VirtualSystemDescription> &vsdescThis,
OVFFormat enFormat,
XMLStack &stack);
HRESULT writeFS(const LocationInfo &locInfo, const OVFFormat enFormat, ComObjPtr<Progress> &pProgress);
HRESULT writeS3(TaskOVF *pTask);
friend class Machine;
};
struct VirtualSystemDescriptionEntry
{
uint32_t ulIndex; // zero-based index of this entry within array
VirtualSystemDescriptionType_T type; // type of this entry
Utf8Str strRef; // reference number (hard disk controllers only)
Utf8Str strOvf; // original OVF value (type-dependent)
Utf8Str strVbox; // configuration value (type-dependent)
Utf8Str strExtraConfig; // extra configuration key=value strings (type-dependent)
uint32_t ulSizeMB; // hard disk images only: size of the uncompressed image in MB
};
class ATL_NO_VTABLE VirtualSystemDescription :
public VirtualBoxBase,
public VirtualBoxSupportErrorInfoImpl<VirtualSystemDescription, IVirtualSystemDescription>,
public VirtualBoxSupportTranslation<VirtualSystemDescription>,
VBOX_SCRIPTABLE_IMPL(IVirtualSystemDescription)
{
friend class Appliance;
public:
VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT (VirtualSystemDescription)
DECLARE_NOT_AGGREGATABLE(VirtualSystemDescription)
DECLARE_PROTECT_FINAL_CONSTRUCT()
BEGIN_COM_MAP(VirtualSystemDescription)
COM_INTERFACE_ENTRY(ISupportErrorInfo)
COM_INTERFACE_ENTRY(IVirtualSystemDescription)
COM_INTERFACE_ENTRY(IDispatch)
END_COM_MAP()
DECLARE_EMPTY_CTOR_DTOR (VirtualSystemDescription)
// public initializer/uninitializer for internal purposes only
HRESULT FinalConstruct() { return S_OK; }
void FinalRelease() { uninit(); }
HRESULT init();
void uninit();
// for VirtualBoxSupportErrorInfoImpl
static const wchar_t *getComponentName() { return L"VirtualSystemDescription"; }
/* IVirtualSystemDescription properties */
STDMETHOD(COMGETTER(Count))(ULONG *aCount);
/* IVirtualSystemDescription methods */
STDMETHOD(GetDescription)(ComSafeArrayOut(VirtualSystemDescriptionType_T, aTypes),
ComSafeArrayOut(BSTR, aRefs),
ComSafeArrayOut(BSTR, aOvfValues),
ComSafeArrayOut(BSTR, aVboxValues),
ComSafeArrayOut(BSTR, aExtraConfigValues));
STDMETHOD(GetDescriptionByType)(VirtualSystemDescriptionType_T aType,
ComSafeArrayOut(VirtualSystemDescriptionType_T, aTypes),
ComSafeArrayOut(BSTR, aRefs),
ComSafeArrayOut(BSTR, aOvfValues),
ComSafeArrayOut(BSTR, aVboxValues),
ComSafeArrayOut(BSTR, aExtraConfigValues));
STDMETHOD(GetValuesByType)(VirtualSystemDescriptionType_T aType,
VirtualSystemDescriptionValueType_T aWhich,
ComSafeArrayOut(BSTR, aValues));
STDMETHOD(SetFinalValues)(ComSafeArrayIn(BOOL, aEnabled),
ComSafeArrayIn(IN_BSTR, aVboxValues),
ComSafeArrayIn(IN_BSTR, aExtraConfigValues));
STDMETHOD(AddDescription)(VirtualSystemDescriptionType_T aType,
IN_BSTR aVboxValue,
IN_BSTR aExtraConfigValue);
/* public methods only for internal purposes */
void addEntry(VirtualSystemDescriptionType_T aType,
const Utf8Str &strRef,
const Utf8Str &aOrigValue,
const Utf8Str &aAutoValue,
uint32_t ulSizeMB = 0,
const Utf8Str &strExtraConfig = "");
std::list<VirtualSystemDescriptionEntry*> findByType(VirtualSystemDescriptionType_T aType);
const VirtualSystemDescriptionEntry* findControllerFromID(uint32_t id);
/* private instance data */
private:
struct Data;
Data *m;
friend class Machine;
};
#endif // ____H_APPLIANCEIMPL
/* vi: set tabstop=4 shiftwidth=4 expandtab: */