1 | /* $Id: ApplianceImpl.h 32837 2010-09-30 08:42:36Z 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 |
|
---|
136 | HRESULT readImpl(const LocationInfo &aLocInfo, ComObjPtr<Progress> &aProgress);
|
---|
137 |
|
---|
138 | struct TaskOVF;
|
---|
139 | static DECLCALLBACK(int) taskThreadImportOrExport(RTTHREAD aThread, void *pvUser);
|
---|
140 |
|
---|
141 | HRESULT readFS(const LocationInfo &locInfo, ComObjPtr<Progress> &pProgress);
|
---|
142 | HRESULT readFSOVF(const LocationInfo &locInfo, ComObjPtr<Progress> &pProgress);
|
---|
143 | HRESULT readFSOVA(const LocationInfo &locInfo, ComObjPtr<Progress> &pProgress);
|
---|
144 | HRESULT readS3(TaskOVF *pTask);
|
---|
145 |
|
---|
146 | void convertDiskAttachmentValues(const ovf::HardDiskController &hdc,
|
---|
147 | uint32_t ulAddressOnParent,
|
---|
148 | Bstr &controllerType,
|
---|
149 | int32_t &lControllerPort,
|
---|
150 | int32_t &lDevice);
|
---|
151 |
|
---|
152 | HRESULT importImpl(const LocationInfo &aLocInfo, ComObjPtr<Progress> &aProgress);
|
---|
153 | HRESULT manifestVerify(const LocationInfo &locInfo, const ovf::OVFReader &reader, ComObjPtr<Progress> &pProgress);
|
---|
154 |
|
---|
155 | HRESULT importFS(TaskOVF *pTask);
|
---|
156 | HRESULT importFSOVF(TaskOVF *pTask);
|
---|
157 | HRESULT importFSOVA(TaskOVF *pTask);
|
---|
158 |
|
---|
159 | struct ImportStack;
|
---|
160 | void importOneDiskImage(const ovf::DiskImage &di,
|
---|
161 | const Utf8Str &strTargetPath,
|
---|
162 | ComPtr<IMedium> &pTargetHD,
|
---|
163 | ImportStack &stack);
|
---|
164 | void importMachineGeneric(const ovf::VirtualSystem &vsysThis,
|
---|
165 | ComObjPtr<VirtualSystemDescription> &vsdescThis,
|
---|
166 | ComPtr<IMachine> &pNewMachine,
|
---|
167 | ImportStack &stack);
|
---|
168 | void importVBoxMachine(ComObjPtr<VirtualSystemDescription> &vsdescThis,
|
---|
169 | ComPtr<IMachine> &pNewMachine,
|
---|
170 | ImportStack &stack);
|
---|
171 |
|
---|
172 | HRESULT importS3(TaskOVF *pTask);
|
---|
173 |
|
---|
174 | HRESULT writeImpl(OVFFormat aFormat, const LocationInfo &aLocInfo, ComObjPtr<Progress> &aProgress);
|
---|
175 |
|
---|
176 | struct XMLStack;
|
---|
177 | void buildXML(AutoWriteLockBase& writeLock, xml::Document &doc, XMLStack &stack, const Utf8Str &strPath, OVFFormat enFormat);
|
---|
178 | void buildXMLForOneVirtualSystem(AutoWriteLockBase& writeLock,
|
---|
179 | xml::ElementNode &elmToAddVirtualSystemsTo,
|
---|
180 | std::list<xml::ElementNode*> *pllElementsWithUuidAttributes,
|
---|
181 | ComObjPtr<VirtualSystemDescription> &vsdescThis,
|
---|
182 | OVFFormat enFormat,
|
---|
183 | XMLStack &stack);
|
---|
184 |
|
---|
185 | HRESULT writeFS(TaskOVF *pTask);
|
---|
186 | HRESULT writeFSOVF(TaskOVF *pTask);
|
---|
187 | HRESULT writeFSOVA(TaskOVF *pTask);
|
---|
188 | HRESULT writeS3(TaskOVF *pTask);
|
---|
189 |
|
---|
190 | friend class Machine;
|
---|
191 | };
|
---|
192 |
|
---|
193 | struct VirtualSystemDescriptionEntry
|
---|
194 | {
|
---|
195 | uint32_t ulIndex; // zero-based index of this entry within array
|
---|
196 | VirtualSystemDescriptionType_T type; // type of this entry
|
---|
197 | Utf8Str strRef; // reference number (hard disk controllers only)
|
---|
198 | Utf8Str strOvf; // original OVF value (type-dependent)
|
---|
199 | Utf8Str strVboxSuggested; // configuration value (type-dependent); original value suggested by interpret()
|
---|
200 | Utf8Str strVboxCurrent; // configuration value (type-dependent); current value, either from interpret() or setFinalValue()
|
---|
201 | Utf8Str strExtraConfigSuggested; // extra configuration key=value strings (type-dependent); original value suggested by interpret()
|
---|
202 | Utf8Str strExtraConfigCurrent; // extra configuration key=value strings (type-dependent); current value, either from interpret() or setFinalValue()
|
---|
203 |
|
---|
204 | uint32_t ulSizeMB; // hard disk images only: a copy of ovf::DiskImage::ulSuggestedSizeMB
|
---|
205 | };
|
---|
206 |
|
---|
207 | class ATL_NO_VTABLE VirtualSystemDescription :
|
---|
208 | public VirtualBoxBase,
|
---|
209 | VBOX_SCRIPTABLE_IMPL(IVirtualSystemDescription)
|
---|
210 | {
|
---|
211 | friend class Appliance;
|
---|
212 |
|
---|
213 | public:
|
---|
214 | VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(VirtualSystemDescription, IVirtualSystemDescription)
|
---|
215 |
|
---|
216 | DECLARE_NOT_AGGREGATABLE(VirtualSystemDescription)
|
---|
217 |
|
---|
218 | DECLARE_PROTECT_FINAL_CONSTRUCT()
|
---|
219 |
|
---|
220 | BEGIN_COM_MAP(VirtualSystemDescription)
|
---|
221 | COM_INTERFACE_ENTRY(ISupportErrorInfo)
|
---|
222 | COM_INTERFACE_ENTRY(IVirtualSystemDescription)
|
---|
223 | COM_INTERFACE_ENTRY(IDispatch)
|
---|
224 | END_COM_MAP()
|
---|
225 |
|
---|
226 | DECLARE_EMPTY_CTOR_DTOR (VirtualSystemDescription)
|
---|
227 |
|
---|
228 | // public initializer/uninitializer for internal purposes only
|
---|
229 | HRESULT FinalConstruct() { return S_OK; }
|
---|
230 | void FinalRelease() { uninit(); }
|
---|
231 |
|
---|
232 | HRESULT init();
|
---|
233 | void uninit();
|
---|
234 |
|
---|
235 | /* IVirtualSystemDescription properties */
|
---|
236 | STDMETHOD(COMGETTER(Count))(ULONG *aCount);
|
---|
237 |
|
---|
238 | /* IVirtualSystemDescription methods */
|
---|
239 | STDMETHOD(GetDescription)(ComSafeArrayOut(VirtualSystemDescriptionType_T, aTypes),
|
---|
240 | ComSafeArrayOut(BSTR, aRefs),
|
---|
241 | ComSafeArrayOut(BSTR, aOvfValues),
|
---|
242 | ComSafeArrayOut(BSTR, aVboxValues),
|
---|
243 | ComSafeArrayOut(BSTR, aExtraConfigValues));
|
---|
244 |
|
---|
245 | STDMETHOD(GetDescriptionByType)(VirtualSystemDescriptionType_T aType,
|
---|
246 | ComSafeArrayOut(VirtualSystemDescriptionType_T, aTypes),
|
---|
247 | ComSafeArrayOut(BSTR, aRefs),
|
---|
248 | ComSafeArrayOut(BSTR, aOvfValues),
|
---|
249 | ComSafeArrayOut(BSTR, aVboxValues),
|
---|
250 | ComSafeArrayOut(BSTR, aExtraConfigValues));
|
---|
251 |
|
---|
252 | STDMETHOD(GetValuesByType)(VirtualSystemDescriptionType_T aType,
|
---|
253 | VirtualSystemDescriptionValueType_T aWhich,
|
---|
254 | ComSafeArrayOut(BSTR, aValues));
|
---|
255 |
|
---|
256 | STDMETHOD(SetFinalValues)(ComSafeArrayIn(BOOL, aEnabled),
|
---|
257 | ComSafeArrayIn(IN_BSTR, aVboxValues),
|
---|
258 | ComSafeArrayIn(IN_BSTR, aExtraConfigValues));
|
---|
259 |
|
---|
260 | STDMETHOD(AddDescription)(VirtualSystemDescriptionType_T aType,
|
---|
261 | IN_BSTR aVboxValue,
|
---|
262 | IN_BSTR aExtraConfigValue);
|
---|
263 |
|
---|
264 | /* public methods only for internal purposes */
|
---|
265 |
|
---|
266 | void addEntry(VirtualSystemDescriptionType_T aType,
|
---|
267 | const Utf8Str &strRef,
|
---|
268 | const Utf8Str &aOvfValue,
|
---|
269 | const Utf8Str &aVboxValue,
|
---|
270 | uint32_t ulSizeMB = 0,
|
---|
271 | const Utf8Str &strExtraConfig = "");
|
---|
272 |
|
---|
273 | std::list<VirtualSystemDescriptionEntry*> findByType(VirtualSystemDescriptionType_T aType);
|
---|
274 | const VirtualSystemDescriptionEntry* findControllerFromID(uint32_t id);
|
---|
275 |
|
---|
276 | void importVboxMachineXML(const xml::ElementNode &elmMachine);
|
---|
277 | const settings::MachineConfigFile* getMachineConfig() const;
|
---|
278 |
|
---|
279 | /* private instance data */
|
---|
280 | private:
|
---|
281 | struct Data;
|
---|
282 | Data *m;
|
---|
283 |
|
---|
284 | friend class Machine;
|
---|
285 | };
|
---|
286 |
|
---|
287 | #endif // ____H_APPLIANCEIMPL
|
---|
288 | /* vi: set tabstop=4 shiftwidth=4 expandtab: */
|
---|