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