VirtualBox

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

Last change on this file since 33386 was 33368, checked in by vboxsync, 14 years ago

Main-OVF: back to const ref

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