VirtualBox

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

Last change on this file since 49935 was 49760, checked in by vboxsync, 11 years ago

6813 stage 2 rev 4

  • 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 49760 2013-12-03 17:57:11Z vboxsync $ */
2
3/** @file
4 *
5 * VirtualBox COM class implementation
6 */
7
8/*
9 * Copyright (C) 2006-2013 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 <VBox/settings.h>
25#include "VirtualSystemDescriptionWrap.h"
26#include "ApplianceWrap.h"
27#include "MediumFormatImpl.h"
28
29/* Todo: This file needs massive cleanup. Split IAppliance in a public and
30 * private classes. */
31#include <iprt/tar.h>
32#include "ovfreader.h"
33#include <set>
34
35/* VBox forward declarations */
36class Progress;
37class VirtualSystemDescription;
38struct VirtualSystemDescriptionEntry;
39struct LocationInfo;
40typedef struct VDINTERFACE *PVDINTERFACE;
41typedef struct VDINTERFACEIO *PVDINTERFACEIO;
42typedef struct SHASTORAGE *PSHASTORAGE;
43
44typedef enum applianceIOName { applianceIOTar, applianceIOFile, applianceIOSha } APPLIANCEIONAME;
45
46namespace ovf
47{
48 struct HardDiskController;
49 struct VirtualSystem;
50 class OVFReader;
51 struct DiskImage;
52 struct EnvelopeData;
53}
54
55namespace xml
56{
57 class Document;
58 class ElementNode;
59}
60
61namespace settings
62{
63 class MachineConfigFile;
64}
65
66class ATL_NO_VTABLE Appliance :
67 public ApplianceWrap
68{
69public:
70
71 DECLARE_EMPTY_CTOR_DTOR(Appliance)
72
73 HRESULT FinalConstruct();
74 void FinalRelease();
75
76
77 HRESULT init(VirtualBox *aVirtualBox);
78 void uninit();
79
80 /* public methods only for internal purposes */
81
82 static HRESULT i_setErrorStatic(HRESULT aResultCode,
83 const Utf8Str &aText)
84 {
85 return setErrorInternal(aResultCode, getStaticClassIID(), getStaticComponentName(), aText, false, true);
86 }
87
88 /* private instance data */
89private:
90 // wrapped IAppliance properties
91 HRESULT getPath(com::Utf8Str &aPath);
92 HRESULT getDisks(std::vector<com::Utf8Str> &aDisks);
93 HRESULT getVirtualSystemDescriptions(std::vector<ComPtr<IVirtualSystemDescription> > &aVirtualSystemDescriptions);
94 HRESULT getMachines(std::vector<com::Utf8Str> &aMachines);
95
96 // wrapped IAppliance methods
97 HRESULT read(const com::Utf8Str &aFile,
98 ComPtr<IProgress> &aProgress);
99 HRESULT interpret();
100 HRESULT importMachines(const std::vector<ImportOptions_T> &aOptions,
101 ComPtr<IProgress> &aProgress);
102 HRESULT createVFSExplorer(const com::Utf8Str &aURI,
103 ComPtr<IVFSExplorer> &aExplorer);
104 HRESULT write(const com::Utf8Str &aFormat,
105 const std::vector<ExportOptions_T> &aOptions,
106 const com::Utf8Str &aPath,
107 ComPtr<IProgress> &aProgress);
108 HRESULT getWarnings(std::vector<com::Utf8Str> &aWarnings);
109
110 /** weak VirtualBox parent */
111 VirtualBox* const mVirtualBox;
112
113 struct ImportStack;
114 struct TaskOVF;
115 struct Data; // opaque, defined in ApplianceImpl.cpp
116 Data *m;
117
118 enum SetUpProgressMode { ImportFile, ImportS3, WriteFile, WriteS3 };
119
120 /*******************************************************************************
121 * General stuff
122 ******************************************************************************/
123
124 bool i_isApplianceIdle();
125 HRESULT i_searchUniqueVMName(Utf8Str& aName) const;
126 HRESULT i_searchUniqueDiskImageFilePath(Utf8Str& aName) const;
127 HRESULT i_setUpProgress(ComObjPtr<Progress> &pProgress,
128 const Bstr &bstrDescription,
129 SetUpProgressMode mode);
130 void i_waitForAsyncProgress(ComObjPtr<Progress> &pProgressThis, ComPtr<IProgress> &pProgressAsync);
131 void i_addWarning(const char* aWarning, ...);
132 void i_disksWeight();
133 void i_parseBucket(Utf8Str &aPath, Utf8Str &aBucket);
134
135 static DECLCALLBACK(int) i_taskThreadImportOrExport(RTTHREAD aThread, void *pvUser);
136
137 HRESULT i_initSetOfSupportedStandardsURI();
138
139 Utf8Str i_typeOfVirtualDiskFormatFromURI(Utf8Str type) const;
140
141 std::set<Utf8Str> i_URIFromTypeOfVirtualDiskFormat(Utf8Str type);
142
143 HRESULT i_initApplianceIONameMap();
144
145 Utf8Str i_applianceIOName(APPLIANCEIONAME type) const;
146
147 HRESULT i_findMediumFormatFromDiskImage(const ovf::DiskImage &di, ComObjPtr<MediumFormat>& mf);
148
149 /*******************************************************************************
150 * Read stuff
151 ******************************************************************************/
152
153 HRESULT i_readImpl(const LocationInfo &aLocInfo, ComObjPtr<Progress> &aProgress);
154
155 HRESULT i_readFS(TaskOVF *pTask);
156 HRESULT i_readFSOVF(TaskOVF *pTask);
157 HRESULT i_readFSOVA(TaskOVF *pTask);
158 HRESULT i_readFSImpl(TaskOVF *pTask, const RTCString &strFilename, PVDINTERFACEIO pCallbacks, PSHASTORAGE pStorage);
159 HRESULT i_readS3(TaskOVF *pTask);
160
161 /*******************************************************************************
162 * Import stuff
163 ******************************************************************************/
164
165 HRESULT i_importImpl(const LocationInfo &aLocInfo, ComObjPtr<Progress> &aProgress);
166
167 HRESULT i_importFS(TaskOVF *pTask);
168 HRESULT i_importFSOVF(TaskOVF *pTask, AutoWriteLockBase& writeLock);
169 HRESULT i_importFSOVA(TaskOVF *pTask, AutoWriteLockBase& writeLock);
170 HRESULT i_importS3(TaskOVF *pTask);
171
172 HRESULT i_readFileToBuf(const Utf8Str &strFile,
173 void **ppvBuf,
174 size_t *pcbSize,
175 bool fCreateDigest,
176 PVDINTERFACEIO pCallbacks,
177 PSHASTORAGE pStorage);
178 HRESULT i_readTarFileToBuf(RTTAR tar,
179 const Utf8Str &strFile,
180 void **ppvBuf,
181 size_t *pcbSize,
182 bool fCreateDigest,
183 PVDINTERFACEIO pCallbacks,
184 PSHASTORAGE pStorage);
185 HRESULT i_verifyManifestFile(const Utf8Str &strFile, ImportStack &stack, void *pvBuf, size_t cbSize);
186
187 void i_convertDiskAttachmentValues(const ovf::HardDiskController &hdc,
188 uint32_t ulAddressOnParent,
189 Bstr &controllerType,
190 int32_t &lControllerPort,
191 int32_t &lDevice);
192
193 void i_importOneDiskImage(const ovf::DiskImage &di,
194 Utf8Str *strTargetPath,
195 ComObjPtr<Medium> &pTargetHD,
196 ImportStack &stack,
197 PVDINTERFACEIO pCallbacks,
198 PSHASTORAGE pStorage);
199
200 void i_importMachineGeneric(const ovf::VirtualSystem &vsysThis,
201 ComObjPtr<VirtualSystemDescription> &vsdescThis,
202 ComPtr<IMachine> &pNewMachine,
203 ImportStack &stack,
204 PVDINTERFACEIO pCallbacks,
205 PSHASTORAGE pStorage);
206 void i_importVBoxMachine(ComObjPtr<VirtualSystemDescription> &vsdescThis,
207 ComPtr<IMachine> &pNewMachine,
208 ImportStack &stack,
209 PVDINTERFACEIO pCallbacks,
210 PSHASTORAGE pStorage);
211 void i_importMachines(ImportStack &stack,
212 PVDINTERFACEIO pCallbacks,
213 PSHASTORAGE pStorage);
214
215 /*******************************************************************************
216 * Write stuff
217 ******************************************************************************/
218
219 HRESULT i_writeImpl(ovf::OVFVersion_T aFormat, const LocationInfo &aLocInfo, ComObjPtr<Progress> &aProgress);
220
221 HRESULT i_writeFS(TaskOVF *pTask);
222 HRESULT i_writeFSOVF(TaskOVF *pTask, AutoWriteLockBase& writeLock);
223 HRESULT i_writeFSOVA(TaskOVF *pTask, AutoWriteLockBase& writeLock);
224 HRESULT i_writeFSImpl(TaskOVF *pTask, AutoWriteLockBase& writeLock, PVDINTERFACEIO pCallbacks, PSHASTORAGE pStorage);
225 HRESULT i_writeS3(TaskOVF *pTask);
226
227 struct XMLStack;
228
229 void i_buildXML(AutoWriteLockBase& writeLock,
230 xml::Document &doc,
231 XMLStack &stack,
232 const Utf8Str &strPath,
233 ovf::OVFVersion_T enFormat);
234 void i_buildXMLForOneVirtualSystem(AutoWriteLockBase& writeLock,
235 xml::ElementNode &elmToAddVirtualSystemsTo,
236 std::list<xml::ElementNode*> *pllElementsWithUuidAttributes,
237 ComObjPtr<VirtualSystemDescription> &vsdescThis,
238 ovf::OVFVersion_T enFormat,
239 XMLStack &stack);
240
241 HRESULT i_preCheckImageAvailability(PSHASTORAGE pSHAStorage,
242 RTCString &availableImage);
243
244 friend class Machine;
245};
246
247void i_parseURI(Utf8Str strUri, LocationInfo &locInfo);
248
249struct VirtualSystemDescriptionEntry
250{
251 uint32_t ulIndex; // zero-based index of this entry within array
252 VirtualSystemDescriptionType_T type; // type of this entry
253 Utf8Str strRef; // reference number (hard disk controllers only)
254 Utf8Str strOvf; // original OVF value (type-dependent)
255 Utf8Str strVboxSuggested; // configuration value (type-dependent); original value suggested by interpret()
256 Utf8Str strVboxCurrent; // configuration value (type-dependent); current value, either from interpret() or setFinalValue()
257 Utf8Str strExtraConfigSuggested; // extra configuration key=value strings (type-dependent); original value suggested by interpret()
258 Utf8Str strExtraConfigCurrent; // extra configuration key=value strings (type-dependent); current value, either from interpret() or setFinalValue()
259
260 uint32_t ulSizeMB; // hard disk images only: a copy of ovf::DiskImage::ulSuggestedSizeMB
261};
262
263class ATL_NO_VTABLE VirtualSystemDescription :
264 public VirtualSystemDescriptionWrap
265{
266 friend class Appliance;
267
268public:
269
270 DECLARE_EMPTY_CTOR_DTOR(VirtualSystemDescription)
271
272 HRESULT FinalConstruct();
273 void FinalRelease();
274
275 HRESULT init();
276 void uninit();
277
278 /* public methods only for internal purposes */
279 void i_addEntry(VirtualSystemDescriptionType_T aType,
280 const Utf8Str &strRef,
281 const Utf8Str &aOvfValue,
282 const Utf8Str &aVboxValue,
283 uint32_t ulSizeMB = 0,
284 const Utf8Str &strExtraConfig = "");
285
286 std::list<VirtualSystemDescriptionEntry*> i_findByType(VirtualSystemDescriptionType_T aType);
287 const VirtualSystemDescriptionEntry* i_findControllerFromID(uint32_t id);
288
289 void i_importVboxMachineXML(const xml::ElementNode &elmMachine);
290 const settings::MachineConfigFile* i_getMachineConfig() const;
291
292 /* private instance data */
293private:
294
295 // wrapped IVirtualSystemDescription properties
296 HRESULT getCount(ULONG *aCount);
297
298 // wrapped IVirtualSystemDescription methods
299 HRESULT getDescription(std::vector<VirtualSystemDescriptionType_T> &aTypes,
300 std::vector<com::Utf8Str> &aRefs,
301 std::vector<com::Utf8Str> &aOVFValues,
302 std::vector<com::Utf8Str> &aVBoxValues,
303 std::vector<com::Utf8Str> &aExtraConfigValues);
304 HRESULT getDescriptionByType(VirtualSystemDescriptionType_T aType,
305 std::vector<VirtualSystemDescriptionType_T> &aTypes,
306 std::vector<com::Utf8Str> &aRefs,
307 std::vector<com::Utf8Str> &aOVFValues,
308 std::vector<com::Utf8Str> &aVBoxValues,
309 std::vector<com::Utf8Str> &aExtraConfigValues);
310 HRESULT getValuesByType(VirtualSystemDescriptionType_T aType,
311 VirtualSystemDescriptionValueType_T aWhich,
312 std::vector<com::Utf8Str> &aValues);
313 HRESULT setFinalValues(const std::vector<BOOL> &aEnabled,
314 const std::vector<com::Utf8Str> &aVBoxValues,
315 const std::vector<com::Utf8Str> &aExtraConfigValues);
316 HRESULT addDescription(VirtualSystemDescriptionType_T aType,
317 const com::Utf8Str &aVBoxValue,
318 const com::Utf8Str &aExtraConfigValue);
319 void i_removeByType(VirtualSystemDescriptionType_T aType);
320
321 struct Data;
322 Data *m;
323
324 friend class Machine;
325};
326
327#endif // ____H_APPLIANCEIMPL
328/* 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