1 | /* $Id: ApplianceImpl.h 33060 2010-10-12 12:17:49Z vboxsync $ */
|
---|
2 |
|
---|
3 | /** @file
|
---|
4 | *
|
---|
5 | * VirtualBox COM class implementation
|
---|
6 | */
|
---|
7 |
|
---|
8 | /*
|
---|
9 | * Copyright (C) 2006-2009 Oracle Corporation
|
---|
10 | *
|
---|
11 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
12 | * available from http://www.virtualbox.org. This file is free software;
|
---|
13 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
14 | * General Public License (GPL) as published by the Free Software
|
---|
15 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
16 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
17 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
18 | */
|
---|
19 |
|
---|
20 | #ifndef ____H_APPLIANCEIMPL
|
---|
21 | #define ____H_APPLIANCEIMPL
|
---|
22 |
|
---|
23 | /* VBox includes */
|
---|
24 | #include "VirtualBoxBase.h"
|
---|
25 |
|
---|
26 | /* VBox forward declarations */
|
---|
27 | class Progress;
|
---|
28 | class VirtualSystemDescription;
|
---|
29 | struct VirtualSystemDescriptionEntry;
|
---|
30 | typedef struct VDINTERFACE *PVDINTERFACE;
|
---|
31 | typedef struct VDINTERFACEIO *PVDINTERFACEIO;
|
---|
32 | typedef struct SHA1STORAGE *PSHA1STORAGE;
|
---|
33 |
|
---|
34 | namespace ovf
|
---|
35 | {
|
---|
36 | struct HardDiskController;
|
---|
37 | struct VirtualSystem;
|
---|
38 | class OVFReader;
|
---|
39 | struct DiskImage;
|
---|
40 | }
|
---|
41 |
|
---|
42 | namespace xml
|
---|
43 | {
|
---|
44 | class Document;
|
---|
45 | class ElementNode;
|
---|
46 | }
|
---|
47 |
|
---|
48 | namespace settings
|
---|
49 | {
|
---|
50 | class MachineConfigFile;
|
---|
51 | }
|
---|
52 |
|
---|
53 | class ATL_NO_VTABLE Appliance :
|
---|
54 | public VirtualBoxBase,
|
---|
55 | VBOX_SCRIPTABLE_IMPL(IAppliance)
|
---|
56 | {
|
---|
57 | public:
|
---|
58 | VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(Appliance, IAppliance)
|
---|
59 |
|
---|
60 | DECLARE_NOT_AGGREGATABLE(Appliance)
|
---|
61 |
|
---|
62 | DECLARE_PROTECT_FINAL_CONSTRUCT()
|
---|
63 |
|
---|
64 | BEGIN_COM_MAP(Appliance)
|
---|
65 | COM_INTERFACE_ENTRY(ISupportErrorInfo)
|
---|
66 | COM_INTERFACE_ENTRY(IAppliance)
|
---|
67 | COM_INTERFACE_ENTRY(IDispatch)
|
---|
68 | END_COM_MAP()
|
---|
69 |
|
---|
70 | DECLARE_EMPTY_CTOR_DTOR (Appliance)
|
---|
71 |
|
---|
72 | enum OVFFormat
|
---|
73 | {
|
---|
74 | unspecified,
|
---|
75 | OVF_0_9,
|
---|
76 | OVF_1_0
|
---|
77 | };
|
---|
78 |
|
---|
79 | // public initializer/uninitializer for internal purposes only
|
---|
80 | HRESULT FinalConstruct() { return S_OK; }
|
---|
81 | void FinalRelease() { uninit(); }
|
---|
82 |
|
---|
83 | HRESULT init(VirtualBox *aVirtualBox);
|
---|
84 | void uninit();
|
---|
85 |
|
---|
86 | /* IAppliance properties */
|
---|
87 | STDMETHOD(COMGETTER(Path))(BSTR *aPath);
|
---|
88 | STDMETHOD(COMGETTER(Disks))(ComSafeArrayOut(BSTR, aDisks));
|
---|
89 | STDMETHOD(COMGETTER(VirtualSystemDescriptions))(ComSafeArrayOut(IVirtualSystemDescription*, aVirtualSystemDescriptions));
|
---|
90 | STDMETHOD(COMGETTER(Machines))(ComSafeArrayOut(BSTR, aMachines));
|
---|
91 |
|
---|
92 | /* IAppliance methods */
|
---|
93 | /* Import methods */
|
---|
94 | STDMETHOD(Read)(IN_BSTR path, IProgress **aProgress);
|
---|
95 | STDMETHOD(Interpret)(void);
|
---|
96 | STDMETHOD(ImportMachines)(IProgress **aProgress);
|
---|
97 | /* Export methods */
|
---|
98 | STDMETHOD(CreateVFSExplorer)(IN_BSTR aURI, IVFSExplorer **aExplorer);
|
---|
99 | STDMETHOD(Write)(IN_BSTR format, BOOL fManifest, IN_BSTR path, IProgress **aProgress);
|
---|
100 |
|
---|
101 | STDMETHOD(GetWarnings)(ComSafeArrayOut(BSTR, aWarnings));
|
---|
102 |
|
---|
103 | /* public methods only for internal purposes */
|
---|
104 |
|
---|
105 | static HRESULT setErrorStatic(HRESULT aResultCode,
|
---|
106 | const Utf8Str &aText)
|
---|
107 | {
|
---|
108 | return setErrorInternal(aResultCode, getStaticClassIID(), getStaticComponentName(), aText, false, true);
|
---|
109 | }
|
---|
110 |
|
---|
111 | /* private instance data */
|
---|
112 | private:
|
---|
113 | /** weak VirtualBox parent */
|
---|
114 | VirtualBox* const mVirtualBox;
|
---|
115 |
|
---|
116 | struct Data; // opaque, defined in ApplianceImpl.cpp
|
---|
117 | Data *m;
|
---|
118 |
|
---|
119 | bool isApplianceIdle();
|
---|
120 |
|
---|
121 | HRESULT searchUniqueVMName(Utf8Str& aName) const;
|
---|
122 | HRESULT searchUniqueDiskImageFilePath(Utf8Str& aName) const;
|
---|
123 | HRESULT getDefaultHardDiskFolder(Utf8Str &str) const;
|
---|
124 | void waitForAsyncProgress(ComObjPtr<Progress> &pProgressThis, ComPtr<IProgress> &pProgressAsync);
|
---|
125 | void addWarning(const char* aWarning, ...);
|
---|
126 |
|
---|
127 | void disksWeight();
|
---|
128 | struct LocationInfo;
|
---|
129 | enum SetUpProgressMode { ImportFileWithManifest, ImportFileNoManifest, ImportS3, WriteFile, WriteS3 };
|
---|
130 | HRESULT setUpProgress(const LocationInfo &locInfo,
|
---|
131 | ComObjPtr<Progress> &pProgress,
|
---|
132 | const Bstr &bstrDescription,
|
---|
133 | SetUpProgressMode mode);
|
---|
134 |
|
---|
135 | void parseURI(Utf8Str strUri, LocationInfo &locInfo) const;
|
---|
136 | void parseBucket(Utf8Str &aPath, Utf8Str &aBucket);
|
---|
137 | Utf8Str manifestFileName(const Utf8Str& aPath) const;
|
---|
138 | Utf8Str queryManifestFileName(const Utf8Str& aPath) const;
|
---|
139 |
|
---|
140 | HRESULT readImpl(const LocationInfo &aLocInfo, ComObjPtr<Progress> &aProgress);
|
---|
141 |
|
---|
142 | struct TaskOVF;
|
---|
143 | static DECLCALLBACK(int) taskThreadImportOrExport(RTTHREAD aThread, void *pvUser);
|
---|
144 |
|
---|
145 | HRESULT readFS(const LocationInfo &locInfo, ComObjPtr<Progress> &pProgress);
|
---|
146 | HRESULT readFSOVF(const LocationInfo &locInfo, ComObjPtr<Progress> &pProgress);
|
---|
147 | HRESULT readFSOVA(const LocationInfo &locInfo, ComObjPtr<Progress> &pProgress);
|
---|
148 | HRESULT readS3(TaskOVF *pTask);
|
---|
149 |
|
---|
150 | void convertDiskAttachmentValues(const ovf::HardDiskController &hdc,
|
---|
151 | uint32_t ulAddressOnParent,
|
---|
152 | Bstr &controllerType,
|
---|
153 | int32_t &lControllerPort,
|
---|
154 | int32_t &lDevice);
|
---|
155 |
|
---|
156 | HRESULT importImpl(const LocationInfo &aLocInfo, ComObjPtr<Progress> &aProgress);
|
---|
157 | HRESULT manifestVerify(const LocationInfo &locInfo, const ovf::OVFReader &reader, ComObjPtr<Progress> &pProgress);
|
---|
158 |
|
---|
159 | HRESULT importFS(TaskOVF *pTask);
|
---|
160 | HRESULT importFSOVF(TaskOVF *pTask);
|
---|
161 | HRESULT importFSOVA(TaskOVF *pTask);
|
---|
162 |
|
---|
163 | struct ImportStack;
|
---|
164 | void importOneDiskImage(const ovf::DiskImage &di,
|
---|
165 | const Utf8Str &strTargetPath,
|
---|
166 | ComPtr<IMedium> &pTargetHD,
|
---|
167 | ImportStack &stack);
|
---|
168 | void importMachineGeneric(const ovf::VirtualSystem &vsysThis,
|
---|
169 | ComObjPtr<VirtualSystemDescription> &vsdescThis,
|
---|
170 | ComPtr<IMachine> &pNewMachine,
|
---|
171 | ImportStack &stack);
|
---|
172 | void importVBoxMachine(ComObjPtr<VirtualSystemDescription> &vsdescThis,
|
---|
173 | ComPtr<IMachine> &pNewMachine,
|
---|
174 | ImportStack &stack);
|
---|
175 |
|
---|
176 | HRESULT importS3(TaskOVF *pTask);
|
---|
177 |
|
---|
178 | HRESULT writeImpl(OVFFormat aFormat, const LocationInfo &aLocInfo, ComObjPtr<Progress> &aProgress);
|
---|
179 |
|
---|
180 | struct XMLStack;
|
---|
181 | void buildXML(AutoWriteLockBase& writeLock, xml::Document &doc, XMLStack &stack, const Utf8Str &strPath, OVFFormat enFormat);
|
---|
182 | void buildXMLForOneVirtualSystem(AutoWriteLockBase& writeLock,
|
---|
183 | xml::ElementNode &elmToAddVirtualSystemsTo,
|
---|
184 | std::list<xml::ElementNode*> *pllElementsWithUuidAttributes,
|
---|
185 | ComObjPtr<VirtualSystemDescription> &vsdescThis,
|
---|
186 | OVFFormat enFormat,
|
---|
187 | XMLStack &stack);
|
---|
188 |
|
---|
189 | HRESULT writeFS(TaskOVF *pTask);
|
---|
190 | HRESULT writeFSOVF(TaskOVF *pTask, AutoWriteLockBase& writeLock);
|
---|
191 | HRESULT writeFSOVA(TaskOVF *pTask, AutoWriteLockBase& writeLock);
|
---|
192 | HRESULT writeFSImpl(TaskOVF *pTask, AutoWriteLockBase& writeLock, PVDINTERFACEIO pCallbacks, PSHA1STORAGE pStorage);
|
---|
193 | HRESULT writeS3(TaskOVF *pTask);
|
---|
194 |
|
---|
195 | friend class Machine;
|
---|
196 | };
|
---|
197 |
|
---|
198 | struct VirtualSystemDescriptionEntry
|
---|
199 | {
|
---|
200 | uint32_t ulIndex; // zero-based index of this entry within array
|
---|
201 | VirtualSystemDescriptionType_T type; // type of this entry
|
---|
202 | Utf8Str strRef; // reference number (hard disk controllers only)
|
---|
203 | Utf8Str strOvf; // original OVF value (type-dependent)
|
---|
204 | Utf8Str strVboxSuggested; // configuration value (type-dependent); original value suggested by interpret()
|
---|
205 | Utf8Str strVboxCurrent; // configuration value (type-dependent); current value, either from interpret() or setFinalValue()
|
---|
206 | Utf8Str strExtraConfigSuggested; // extra configuration key=value strings (type-dependent); original value suggested by interpret()
|
---|
207 | Utf8Str strExtraConfigCurrent; // extra configuration key=value strings (type-dependent); current value, either from interpret() or setFinalValue()
|
---|
208 |
|
---|
209 | uint32_t ulSizeMB; // hard disk images only: a copy of ovf::DiskImage::ulSuggestedSizeMB
|
---|
210 | };
|
---|
211 |
|
---|
212 | class ATL_NO_VTABLE VirtualSystemDescription :
|
---|
213 | public VirtualBoxBase,
|
---|
214 | VBOX_SCRIPTABLE_IMPL(IVirtualSystemDescription)
|
---|
215 | {
|
---|
216 | friend class Appliance;
|
---|
217 |
|
---|
218 | public:
|
---|
219 | VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(VirtualSystemDescription, IVirtualSystemDescription)
|
---|
220 |
|
---|
221 | DECLARE_NOT_AGGREGATABLE(VirtualSystemDescription)
|
---|
222 |
|
---|
223 | DECLARE_PROTECT_FINAL_CONSTRUCT()
|
---|
224 |
|
---|
225 | BEGIN_COM_MAP(VirtualSystemDescription)
|
---|
226 | COM_INTERFACE_ENTRY(ISupportErrorInfo)
|
---|
227 | COM_INTERFACE_ENTRY(IVirtualSystemDescription)
|
---|
228 | COM_INTERFACE_ENTRY(IDispatch)
|
---|
229 | END_COM_MAP()
|
---|
230 |
|
---|
231 | DECLARE_EMPTY_CTOR_DTOR (VirtualSystemDescription)
|
---|
232 |
|
---|
233 | // public initializer/uninitializer for internal purposes only
|
---|
234 | HRESULT FinalConstruct() { return S_OK; }
|
---|
235 | void FinalRelease() { uninit(); }
|
---|
236 |
|
---|
237 | HRESULT init();
|
---|
238 | void uninit();
|
---|
239 |
|
---|
240 | /* IVirtualSystemDescription properties */
|
---|
241 | STDMETHOD(COMGETTER(Count))(ULONG *aCount);
|
---|
242 |
|
---|
243 | /* IVirtualSystemDescription methods */
|
---|
244 | STDMETHOD(GetDescription)(ComSafeArrayOut(VirtualSystemDescriptionType_T, aTypes),
|
---|
245 | ComSafeArrayOut(BSTR, aRefs),
|
---|
246 | ComSafeArrayOut(BSTR, aOvfValues),
|
---|
247 | ComSafeArrayOut(BSTR, aVboxValues),
|
---|
248 | ComSafeArrayOut(BSTR, aExtraConfigValues));
|
---|
249 |
|
---|
250 | STDMETHOD(GetDescriptionByType)(VirtualSystemDescriptionType_T aType,
|
---|
251 | ComSafeArrayOut(VirtualSystemDescriptionType_T, aTypes),
|
---|
252 | ComSafeArrayOut(BSTR, aRefs),
|
---|
253 | ComSafeArrayOut(BSTR, aOvfValues),
|
---|
254 | ComSafeArrayOut(BSTR, aVboxValues),
|
---|
255 | ComSafeArrayOut(BSTR, aExtraConfigValues));
|
---|
256 |
|
---|
257 | STDMETHOD(GetValuesByType)(VirtualSystemDescriptionType_T aType,
|
---|
258 | VirtualSystemDescriptionValueType_T aWhich,
|
---|
259 | ComSafeArrayOut(BSTR, aValues));
|
---|
260 |
|
---|
261 | STDMETHOD(SetFinalValues)(ComSafeArrayIn(BOOL, aEnabled),
|
---|
262 | ComSafeArrayIn(IN_BSTR, aVboxValues),
|
---|
263 | ComSafeArrayIn(IN_BSTR, aExtraConfigValues));
|
---|
264 |
|
---|
265 | STDMETHOD(AddDescription)(VirtualSystemDescriptionType_T aType,
|
---|
266 | IN_BSTR aVboxValue,
|
---|
267 | IN_BSTR aExtraConfigValue);
|
---|
268 |
|
---|
269 | /* public methods only for internal purposes */
|
---|
270 |
|
---|
271 | void addEntry(VirtualSystemDescriptionType_T aType,
|
---|
272 | const Utf8Str &strRef,
|
---|
273 | const Utf8Str &aOvfValue,
|
---|
274 | const Utf8Str &aVboxValue,
|
---|
275 | uint32_t ulSizeMB = 0,
|
---|
276 | const Utf8Str &strExtraConfig = "");
|
---|
277 |
|
---|
278 | std::list<VirtualSystemDescriptionEntry*> findByType(VirtualSystemDescriptionType_T aType);
|
---|
279 | const VirtualSystemDescriptionEntry* findControllerFromID(uint32_t id);
|
---|
280 |
|
---|
281 | void importVboxMachineXML(const xml::ElementNode &elmMachine);
|
---|
282 | const settings::MachineConfigFile* getMachineConfig() const;
|
---|
283 |
|
---|
284 | /* private instance data */
|
---|
285 | private:
|
---|
286 | struct Data;
|
---|
287 | Data *m;
|
---|
288 |
|
---|
289 | friend class Machine;
|
---|
290 | };
|
---|
291 |
|
---|
292 | #endif // ____H_APPLIANCEIMPL
|
---|
293 | /* vi: set tabstop=4 shiftwidth=4 expandtab: */
|
---|