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