VirtualBox

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

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

header (C) fixes

  • 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 44528 2013-02-04 14:27:54Z 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/* VBox forward declarations */
31class Progress;
32class VirtualSystemDescription;
33struct VirtualSystemDescriptionEntry;
34struct LocationInfo;
35typedef struct VDINTERFACE *PVDINTERFACE;
36typedef struct VDINTERFACEIO *PVDINTERFACEIO;
37typedef struct SHASTORAGE *PSHASTORAGE;
38
39namespace ovf
40{
41 struct HardDiskController;
42 struct VirtualSystem;
43 class OVFReader;
44 struct DiskImage;
45}
46
47namespace xml
48{
49 class Document;
50 class ElementNode;
51}
52
53namespace settings
54{
55 class MachineConfigFile;
56}
57
58class ATL_NO_VTABLE Appliance :
59 public VirtualBoxBase,
60 VBOX_SCRIPTABLE_IMPL(IAppliance)
61{
62public:
63 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(Appliance, IAppliance)
64
65 DECLARE_NOT_AGGREGATABLE(Appliance)
66
67 DECLARE_PROTECT_FINAL_CONSTRUCT()
68
69 BEGIN_COM_MAP(Appliance)
70 VBOX_DEFAULT_INTERFACE_ENTRIES(IAppliance)
71 END_COM_MAP()
72
73 DECLARE_EMPTY_CTOR_DTOR (Appliance)
74
75 enum OVFFormat
76 {
77 unspecified,
78 OVF_0_9,
79 OVF_1_0,
80 OVF_2_0
81 };
82
83 // public initializer/uninitializer for internal purposes only
84 HRESULT FinalConstruct() { return BaseFinalConstruct(); }
85 void FinalRelease() { uninit(); BaseFinalRelease(); }
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)(ComSafeArrayIn(ImportOptions_T, options), 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 Data; // opaque, defined in ApplianceImpl.cpp
123 Data *m;
124
125 enum SetUpProgressMode { ImportFile, ImportS3, WriteFile, WriteS3 };
126
127 /*******************************************************************************
128 * General stuff
129 ******************************************************************************/
130
131 bool isApplianceIdle();
132 HRESULT searchUniqueVMName(Utf8Str& aName) const;
133 HRESULT searchUniqueDiskImageFilePath(Utf8Str& aName) const;
134 HRESULT setUpProgress(ComObjPtr<Progress> &pProgress,
135 const Bstr &bstrDescription,
136 SetUpProgressMode mode);
137 void waitForAsyncProgress(ComObjPtr<Progress> &pProgressThis, ComPtr<IProgress> &pProgressAsync);
138 void addWarning(const char* aWarning, ...);
139 void disksWeight();
140 void parseBucket(Utf8Str &aPath, Utf8Str &aBucket);
141
142 static DECLCALLBACK(int) taskThreadImportOrExport(RTTHREAD aThread, void *pvUser);
143
144 /*******************************************************************************
145 * Read stuff
146 ******************************************************************************/
147
148 HRESULT readImpl(const LocationInfo &aLocInfo, ComObjPtr<Progress> &aProgress);
149
150 HRESULT readFS(TaskOVF *pTask);
151 HRESULT readFSOVF(TaskOVF *pTask);
152 HRESULT readFSOVA(TaskOVF *pTask);
153 HRESULT readFSImpl(TaskOVF *pTask, const RTCString &strFilename, PVDINTERFACEIO pCallbacks, PSHASTORAGE pStorage);
154 HRESULT readS3(TaskOVF *pTask);
155
156 /*******************************************************************************
157 * Import stuff
158 ******************************************************************************/
159
160 HRESULT importImpl(const LocationInfo &aLocInfo, ComObjPtr<Progress> &aProgress);
161
162 HRESULT importFS(TaskOVF *pTask);
163 HRESULT importFSOVF(TaskOVF *pTask, AutoWriteLockBase& writeLock);
164 HRESULT importFSOVA(TaskOVF *pTask, AutoWriteLockBase& writeLock);
165 HRESULT importS3(TaskOVF *pTask);
166
167 HRESULT readManifestFile(const Utf8Str &strFile, void **ppvBuf, size_t *pcbSize, PVDINTERFACEIO pCallbacks, PSHASTORAGE pStorage);
168 HRESULT readTarManifestFile(RTTAR tar, const Utf8Str &strFile, void **ppvBuf, size_t *pcbSize, PVDINTERFACEIO pCallbacks, PSHASTORAGE pStorage);
169 HRESULT verifyManifestFile(const Utf8Str &strFile, ImportStack &stack, void *pvBuf, size_t cbSize);
170
171 void convertDiskAttachmentValues(const ovf::HardDiskController &hdc,
172 uint32_t ulAddressOnParent,
173 Bstr &controllerType,
174 int32_t &lControllerPort,
175 int32_t &lDevice);
176
177 void importOneDiskImage(const ovf::DiskImage &di,
178 const Utf8Str &strTargetPath,
179 ComObjPtr<Medium> &pTargetHD,
180 ImportStack &stack,
181 PVDINTERFACEIO pCallbacks,
182 PSHASTORAGE pStorage);
183 void importMachineGeneric(const ovf::VirtualSystem &vsysThis,
184 ComObjPtr<VirtualSystemDescription> &vsdescThis,
185 ComPtr<IMachine> &pNewMachine,
186 ImportStack &stack,
187 PVDINTERFACEIO pCallbacks,
188 PSHASTORAGE pStorage);
189 void importVBoxMachine(ComObjPtr<VirtualSystemDescription> &vsdescThis,
190 ComPtr<IMachine> &pNewMachine,
191 ImportStack &stack,
192 PVDINTERFACEIO pCallbacks,
193 PSHASTORAGE pStorage);
194 void importMachines(ImportStack &stack,
195 PVDINTERFACEIO pCallbacks,
196 PSHASTORAGE pStorage);
197
198 /*******************************************************************************
199 * Write stuff
200 ******************************************************************************/
201
202 HRESULT writeImpl(OVFFormat aFormat, const LocationInfo &aLocInfo, ComObjPtr<Progress> &aProgress);
203
204 HRESULT writeFS(TaskOVF *pTask);
205 HRESULT writeFSOVF(TaskOVF *pTask, AutoWriteLockBase& writeLock);
206 HRESULT writeFSOVA(TaskOVF *pTask, AutoWriteLockBase& writeLock);
207 HRESULT writeFSImpl(TaskOVF *pTask, AutoWriteLockBase& writeLock, PVDINTERFACEIO pCallbacks, PSHASTORAGE pStorage);
208 HRESULT writeS3(TaskOVF *pTask);
209
210 struct XMLStack;
211 void buildXML(AutoWriteLockBase& writeLock, xml::Document &doc, XMLStack &stack, const Utf8Str &strPath, OVFFormat enFormat);
212 void buildXMLForOneVirtualSystem(AutoWriteLockBase& writeLock,
213 xml::ElementNode &elmToAddVirtualSystemsTo,
214 std::list<xml::ElementNode*> *pllElementsWithUuidAttributes,
215 ComObjPtr<VirtualSystemDescription> &vsdescThis,
216 OVFFormat enFormat,
217 XMLStack &stack);
218
219
220 friend class Machine;
221};
222
223void parseURI(Utf8Str strUri, LocationInfo &locInfo);
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 VBOX_DEFAULT_INTERFACE_ENTRIES(IVirtualSystemDescription)
254 END_COM_MAP()
255
256 DECLARE_EMPTY_CTOR_DTOR (VirtualSystemDescription)
257
258 // public initializer/uninitializer for internal purposes only
259 HRESULT FinalConstruct() { return BaseFinalConstruct(); }
260 void FinalRelease() { uninit(); BaseFinalRelease(); }
261
262 HRESULT init();
263 void uninit();
264
265 /* IVirtualSystemDescription properties */
266 STDMETHOD(COMGETTER(Count))(ULONG *aCount);
267
268 /* IVirtualSystemDescription methods */
269 STDMETHOD(GetDescription)(ComSafeArrayOut(VirtualSystemDescriptionType_T, aTypes),
270 ComSafeArrayOut(BSTR, aRefs),
271 ComSafeArrayOut(BSTR, aOvfValues),
272 ComSafeArrayOut(BSTR, aVboxValues),
273 ComSafeArrayOut(BSTR, aExtraConfigValues));
274
275 STDMETHOD(GetDescriptionByType)(VirtualSystemDescriptionType_T aType,
276 ComSafeArrayOut(VirtualSystemDescriptionType_T, aTypes),
277 ComSafeArrayOut(BSTR, aRefs),
278 ComSafeArrayOut(BSTR, aOvfValues),
279 ComSafeArrayOut(BSTR, aVboxValues),
280 ComSafeArrayOut(BSTR, aExtraConfigValues));
281
282 STDMETHOD(GetValuesByType)(VirtualSystemDescriptionType_T aType,
283 VirtualSystemDescriptionValueType_T aWhich,
284 ComSafeArrayOut(BSTR, aValues));
285
286 STDMETHOD(SetFinalValues)(ComSafeArrayIn(BOOL, aEnabled),
287 ComSafeArrayIn(IN_BSTR, aVboxValues),
288 ComSafeArrayIn(IN_BSTR, aExtraConfigValues));
289
290 STDMETHOD(AddDescription)(VirtualSystemDescriptionType_T aType,
291 IN_BSTR aVboxValue,
292 IN_BSTR aExtraConfigValue);
293
294 /* public methods only for internal purposes */
295
296 void addEntry(VirtualSystemDescriptionType_T aType,
297 const Utf8Str &strRef,
298 const Utf8Str &aOvfValue,
299 const Utf8Str &aVboxValue,
300 uint32_t ulSizeMB = 0,
301 const Utf8Str &strExtraConfig = "");
302
303 std::list<VirtualSystemDescriptionEntry*> findByType(VirtualSystemDescriptionType_T aType);
304 const VirtualSystemDescriptionEntry* findControllerFromID(uint32_t id);
305
306 void importVboxMachineXML(const xml::ElementNode &elmMachine);
307 const settings::MachineConfigFile* getMachineConfig() const;
308
309 /* private instance data */
310private:
311 struct Data;
312 Data *m;
313
314 friend class Machine;
315};
316
317#endif // ____H_APPLIANCEIMPL
318/* 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