VirtualBox

source: vbox/trunk/src/VBox/Main/include/ApplianceImpl.h@ 46775

Last change on this file since 46775 was 46518, checked in by vboxsync, 12 years ago

Export/import OVA/OVF package supports ISO images. The problem with the wrong search files in the archive has been resolved. (see #5429). 2 new elements SASD and EPASD were added in the OVF XML file structure (see #6022).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 13.0 KB
Line 
1/* $Id: ApplianceImpl.h 46518 2013-06-13 10:07:09Z vboxsync $ */
2
3/** @file
4 *
5 * VirtualBox COM class implementation
6 */
7
8/*
9 * Copyright (C) 2006-2012 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/* Todo: This file needs massive cleanup. Split IAppliance in a public and
27 * private classes. */
28#include <iprt/tar.h>
29#include <iprt/circbuf.h>
30#include <VBox/vd.h>
31#include <iprt/sha.h>
32
33#include "ovfreader.h"
34#include <set>
35
36/* VBox forward declarations */
37class Progress;
38class VirtualSystemDescription;
39struct VirtualSystemDescriptionEntry;
40struct LocationInfo;
41typedef struct VDINTERFACE *PVDINTERFACE;
42typedef struct VDINTERFACEIO *PVDINTERFACEIO;
43typedef struct SHASTORAGE *PSHASTORAGE;
44
45typedef enum applianceIOName { applianceIOTar, applianceIOFile } APPLIANCEIONAME;
46
47namespace ovf
48{
49 struct HardDiskController;
50 struct VirtualSystem;
51 class OVFReader;
52 struct DiskImage;
53 struct EnvelopeData;
54}
55
56namespace xml
57{
58 class Document;
59 class ElementNode;
60}
61
62namespace settings
63{
64 class MachineConfigFile;
65}
66
67class ATL_NO_VTABLE Appliance :
68 public VirtualBoxBase,
69 VBOX_SCRIPTABLE_IMPL(IAppliance)
70{
71public:
72 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(Appliance, IAppliance)
73
74 DECLARE_NOT_AGGREGATABLE(Appliance)
75
76 DECLARE_PROTECT_FINAL_CONSTRUCT()
77
78 BEGIN_COM_MAP(Appliance)
79 VBOX_DEFAULT_INTERFACE_ENTRIES(IAppliance)
80 END_COM_MAP()
81
82 DECLARE_EMPTY_CTOR_DTOR (Appliance)
83
84
85
86 // public initializer/uninitializer for internal purposes only
87 HRESULT FinalConstruct() { return BaseFinalConstruct(); }
88 void FinalRelease() { uninit(); BaseFinalRelease(); }
89
90 HRESULT init(VirtualBox *aVirtualBox);
91 void uninit();
92
93 /* IAppliance properties */
94 STDMETHOD(COMGETTER(Path))(BSTR *aPath);
95 STDMETHOD(COMGETTER(Disks))(ComSafeArrayOut(BSTR, aDisks));
96 STDMETHOD(COMGETTER(VirtualSystemDescriptions))(ComSafeArrayOut(IVirtualSystemDescription*, aVirtualSystemDescriptions));
97 STDMETHOD(COMGETTER(Machines))(ComSafeArrayOut(BSTR, aMachines));
98
99 /* IAppliance methods */
100 /* Import methods */
101 STDMETHOD(Read)(IN_BSTR path, IProgress **aProgress);
102 STDMETHOD(Interpret)(void);
103 STDMETHOD(ImportMachines)(ComSafeArrayIn(ImportOptions_T, options), IProgress **aProgress);
104 /* Export methods */
105 STDMETHOD(CreateVFSExplorer)(IN_BSTR aURI, IVFSExplorer **aExplorer);
106 STDMETHOD(Write)(IN_BSTR format, BOOL fManifest, IN_BSTR path, IProgress **aProgress);
107
108 STDMETHOD(GetWarnings)(ComSafeArrayOut(BSTR, aWarnings));
109
110 /* public methods only for internal purposes */
111
112 static HRESULT setErrorStatic(HRESULT aResultCode,
113 const Utf8Str &aText)
114 {
115 return setErrorInternal(aResultCode, getStaticClassIID(), getStaticComponentName(), aText, false, true);
116 }
117
118 /* private instance data */
119private:
120 /** weak VirtualBox parent */
121 VirtualBox* const mVirtualBox;
122
123 struct ImportStack;
124 struct TaskOVF;
125 struct Data; // opaque, defined in ApplianceImpl.cpp
126 Data *m;
127
128 enum SetUpProgressMode { ImportFile, ImportS3, WriteFile, WriteS3 };
129
130 /*******************************************************************************
131 * General stuff
132 ******************************************************************************/
133
134 bool isApplianceIdle();
135 HRESULT searchUniqueVMName(Utf8Str& aName) const;
136 HRESULT searchUniqueDiskImageFilePath(Utf8Str& aName) const;
137 HRESULT setUpProgress(ComObjPtr<Progress> &pProgress,
138 const Bstr &bstrDescription,
139 SetUpProgressMode mode);
140 void waitForAsyncProgress(ComObjPtr<Progress> &pProgressThis, ComPtr<IProgress> &pProgressAsync);
141 void addWarning(const char* aWarning, ...);
142 void disksWeight();
143 void parseBucket(Utf8Str &aPath, Utf8Str &aBucket);
144
145 static DECLCALLBACK(int) taskThreadImportOrExport(RTTHREAD aThread, void *pvUser);
146
147 HRESULT initSetOfSupportedStandardsURI();
148
149 Utf8Str typeOfVirtualDiskFormatFromURI(Utf8Str type) const;
150
151 std::set<Utf8Str> URIFromTypeOfVirtualDiskFormat(Utf8Str type);
152
153 HRESULT initApplianceIONameMap();
154
155 Utf8Str applianceIOName(APPLIANCEIONAME type) const;
156
157 /*******************************************************************************
158 * Read stuff
159 ******************************************************************************/
160
161 HRESULT readImpl(const LocationInfo &aLocInfo, ComObjPtr<Progress> &aProgress);
162
163 HRESULT readFS(TaskOVF *pTask);
164 HRESULT readFSOVF(TaskOVF *pTask);
165 HRESULT readFSOVA(TaskOVF *pTask);
166 HRESULT readFSImpl(TaskOVF *pTask, const RTCString &strFilename, PVDINTERFACEIO pCallbacks, PSHASTORAGE pStorage);
167 HRESULT readS3(TaskOVF *pTask);
168
169 /*******************************************************************************
170 * Import stuff
171 ******************************************************************************/
172
173 HRESULT importImpl(const LocationInfo &aLocInfo, ComObjPtr<Progress> &aProgress);
174
175 HRESULT importFS(TaskOVF *pTask);
176 HRESULT importFSOVF(TaskOVF *pTask, AutoWriteLockBase& writeLock);
177 HRESULT importFSOVA(TaskOVF *pTask, AutoWriteLockBase& writeLock);
178 HRESULT importS3(TaskOVF *pTask);
179
180 HRESULT readManifestFile(const Utf8Str &strFile, void **ppvBuf, size_t *pcbSize, PVDINTERFACEIO pCallbacks, PSHASTORAGE pStorage);
181 HRESULT readTarManifestFile(RTTAR tar, const Utf8Str &strFile, void **ppvBuf, size_t *pcbSize, PVDINTERFACEIO pCallbacks, PSHASTORAGE pStorage);
182 HRESULT verifyManifestFile(const Utf8Str &strFile, ImportStack &stack, void *pvBuf, size_t cbSize);
183
184 void convertDiskAttachmentValues(const ovf::HardDiskController &hdc,
185 uint32_t ulAddressOnParent,
186 Bstr &controllerType,
187 int32_t &lControllerPort,
188 int32_t &lDevice);
189
190 void importOneDiskImage(const ovf::DiskImage &di,
191 const Utf8Str &strTargetPath,
192 ComObjPtr<Medium> &pTargetHD,
193 ImportStack &stack,
194 PVDINTERFACEIO pCallbacks,
195 PSHASTORAGE pStorage);
196
197 void importMachineGeneric(const ovf::VirtualSystem &vsysThis,
198 ComObjPtr<VirtualSystemDescription> &vsdescThis,
199 ComPtr<IMachine> &pNewMachine,
200 ImportStack &stack,
201 PVDINTERFACEIO pCallbacks,
202 PSHASTORAGE pStorage);
203 void importVBoxMachine(ComObjPtr<VirtualSystemDescription> &vsdescThis,
204 ComPtr<IMachine> &pNewMachine,
205 ImportStack &stack,
206 PVDINTERFACEIO pCallbacks,
207 PSHASTORAGE pStorage);
208 void importMachines(ImportStack &stack,
209 PVDINTERFACEIO pCallbacks,
210 PSHASTORAGE pStorage);
211
212 /*******************************************************************************
213 * Write stuff
214 ******************************************************************************/
215
216 HRESULT writeImpl(ovf::OVFVersion_T aFormat, const LocationInfo &aLocInfo, ComObjPtr<Progress> &aProgress);
217
218 HRESULT writeFS(TaskOVF *pTask);
219 HRESULT writeFSOVF(TaskOVF *pTask, AutoWriteLockBase& writeLock);
220 HRESULT writeFSOVA(TaskOVF *pTask, AutoWriteLockBase& writeLock);
221 HRESULT writeFSImpl(TaskOVF *pTask, AutoWriteLockBase& writeLock, PVDINTERFACEIO pCallbacks, PSHASTORAGE pStorage);
222 HRESULT writeS3(TaskOVF *pTask);
223
224 struct XMLStack;
225
226 void buildXML(AutoWriteLockBase& writeLock,
227 xml::Document &doc,
228 XMLStack &stack,
229 const Utf8Str &strPath,
230 ovf::OVFVersion_T enFormat);
231 void buildXMLForOneVirtualSystem(AutoWriteLockBase& writeLock,
232 xml::ElementNode &elmToAddVirtualSystemsTo,
233 std::list<xml::ElementNode*> *pllElementsWithUuidAttributes,
234 ComObjPtr<VirtualSystemDescription> &vsdescThis,
235 ovf::OVFVersion_T enFormat,
236 XMLStack &stack);
237
238 HRESULT preCheckImageAvailability(PSHASTORAGE pSHAStorage,
239 RTCString &availableImage);
240
241 friend class Machine;
242};
243
244void parseURI(Utf8Str strUri, LocationInfo &locInfo);
245
246struct VirtualSystemDescriptionEntry
247{
248 uint32_t ulIndex; // zero-based index of this entry within array
249 VirtualSystemDescriptionType_T type; // type of this entry
250 Utf8Str strRef; // reference number (hard disk controllers only)
251 Utf8Str strOvf; // original OVF value (type-dependent)
252 Utf8Str strVboxSuggested; // configuration value (type-dependent); original value suggested by interpret()
253 Utf8Str strVboxCurrent; // configuration value (type-dependent); current value, either from interpret() or setFinalValue()
254 Utf8Str strExtraConfigSuggested; // extra configuration key=value strings (type-dependent); original value suggested by interpret()
255 Utf8Str strExtraConfigCurrent; // extra configuration key=value strings (type-dependent); current value, either from interpret() or setFinalValue()
256
257 uint32_t ulSizeMB; // hard disk images only: a copy of ovf::DiskImage::ulSuggestedSizeMB
258};
259
260class ATL_NO_VTABLE VirtualSystemDescription :
261 public VirtualBoxBase,
262 VBOX_SCRIPTABLE_IMPL(IVirtualSystemDescription)
263{
264 friend class Appliance;
265
266public:
267 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(VirtualSystemDescription, IVirtualSystemDescription)
268
269 DECLARE_NOT_AGGREGATABLE(VirtualSystemDescription)
270
271 DECLARE_PROTECT_FINAL_CONSTRUCT()
272
273 BEGIN_COM_MAP(VirtualSystemDescription)
274 VBOX_DEFAULT_INTERFACE_ENTRIES(IVirtualSystemDescription)
275 END_COM_MAP()
276
277 DECLARE_EMPTY_CTOR_DTOR (VirtualSystemDescription)
278
279 // public initializer/uninitializer for internal purposes only
280 HRESULT FinalConstruct() { return BaseFinalConstruct(); }
281 void FinalRelease() { uninit(); BaseFinalRelease(); }
282
283 HRESULT init();
284 void uninit();
285
286 /* IVirtualSystemDescription properties */
287 STDMETHOD(COMGETTER(Count))(ULONG *aCount);
288
289 /* IVirtualSystemDescription methods */
290 STDMETHOD(GetDescription)(ComSafeArrayOut(VirtualSystemDescriptionType_T, aTypes),
291 ComSafeArrayOut(BSTR, aRefs),
292 ComSafeArrayOut(BSTR, aOvfValues),
293 ComSafeArrayOut(BSTR, aVboxValues),
294 ComSafeArrayOut(BSTR, aExtraConfigValues));
295
296 STDMETHOD(GetDescriptionByType)(VirtualSystemDescriptionType_T aType,
297 ComSafeArrayOut(VirtualSystemDescriptionType_T, aTypes),
298 ComSafeArrayOut(BSTR, aRefs),
299 ComSafeArrayOut(BSTR, aOvfValues),
300 ComSafeArrayOut(BSTR, aVboxValues),
301 ComSafeArrayOut(BSTR, aExtraConfigValues));
302
303 STDMETHOD(GetValuesByType)(VirtualSystemDescriptionType_T aType,
304 VirtualSystemDescriptionValueType_T aWhich,
305 ComSafeArrayOut(BSTR, aValues));
306
307 STDMETHOD(SetFinalValues)(ComSafeArrayIn(BOOL, aEnabled),
308 ComSafeArrayIn(IN_BSTR, aVboxValues),
309 ComSafeArrayIn(IN_BSTR, aExtraConfigValues));
310
311 STDMETHOD(AddDescription)(VirtualSystemDescriptionType_T aType,
312 IN_BSTR aVboxValue,
313 IN_BSTR aExtraConfigValue);
314
315 /* public methods only for internal purposes */
316
317 void addEntry(VirtualSystemDescriptionType_T aType,
318 const Utf8Str &strRef,
319 const Utf8Str &aOvfValue,
320 const Utf8Str &aVboxValue,
321 uint32_t ulSizeMB = 0,
322 const Utf8Str &strExtraConfig = "");
323
324 std::list<VirtualSystemDescriptionEntry*> findByType(VirtualSystemDescriptionType_T aType);
325 const VirtualSystemDescriptionEntry* findControllerFromID(uint32_t id);
326
327 void importVboxMachineXML(const xml::ElementNode &elmMachine);
328 const settings::MachineConfigFile* getMachineConfig() const;
329
330 /* private instance data */
331private:
332 struct Data;
333 Data *m;
334
335 friend class Machine;
336};
337
338#endif // ____H_APPLIANCEIMPL
339/* vi: set tabstop=4 shiftwidth=4 expandtab: */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette