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