VirtualBox

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

Last change on this file since 46284 was 45227, checked in by vboxsync, 12 years ago

Main: OVF 2.0 support. Part 1 - SHA256 digest is supported.

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