1 | /* $Id: ApplianceImpl.h 30881 2010-07-16 14:34:31Z 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, 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 | enum SetUpProgressMode { ImportFileWithManifest, ImportFileNoManifest, ImportS3, WriteFile, WriteS3 };
|
---|
125 | HRESULT setUpProgress(ComObjPtr<Progress> &pProgress,
|
---|
126 | const Bstr &bstrDescription,
|
---|
127 | SetUpProgressMode mode);
|
---|
128 |
|
---|
129 | struct LocationInfo;
|
---|
130 | void parseURI(Utf8Str strUri, LocationInfo &locInfo) const;
|
---|
131 | void parseBucket(Utf8Str &aPath, Utf8Str &aBucket);
|
---|
132 | Utf8Str manifestFileName(Utf8Str aPath) const;
|
---|
133 |
|
---|
134 | HRESULT readImpl(const LocationInfo &aLocInfo, ComObjPtr<Progress> &aProgress);
|
---|
135 |
|
---|
136 | struct TaskOVF;
|
---|
137 | static DECLCALLBACK(int) taskThreadImportOrExport(RTTHREAD aThread, void *pvUser);
|
---|
138 |
|
---|
139 | HRESULT readFS(const LocationInfo &locInfo);
|
---|
140 | HRESULT readS3(TaskOVF *pTask);
|
---|
141 |
|
---|
142 | void convertDiskAttachmentValues(const ovf::HardDiskController &hdc,
|
---|
143 | uint32_t ulAddressOnParent,
|
---|
144 | Bstr &controllerType,
|
---|
145 | int32_t &lControllerPort,
|
---|
146 | int32_t &lDevice);
|
---|
147 |
|
---|
148 | HRESULT importImpl(const LocationInfo &aLocInfo, ComObjPtr<Progress> &aProgress);
|
---|
149 | HRESULT manifestVerify(const LocationInfo &locInfo, const ovf::OVFReader &reader, ComObjPtr<Progress> &pProgress);
|
---|
150 |
|
---|
151 | HRESULT importFS(const LocationInfo &locInfo, ComObjPtr<Progress> &aProgress);
|
---|
152 |
|
---|
153 | struct ImportStack;
|
---|
154 | void importOneDiskImage(const ovf::DiskImage &di,
|
---|
155 | const Utf8Str &strTargetPath,
|
---|
156 | ComPtr<IMedium> &pTargetHD,
|
---|
157 | ImportStack &stack);
|
---|
158 | void importMachineGeneric(const ovf::VirtualSystem &vsysThis,
|
---|
159 | ComObjPtr<VirtualSystemDescription> &vsdescThis,
|
---|
160 | ComPtr<IMachine> &pNewMachine,
|
---|
161 | ImportStack &stack);
|
---|
162 | void importVBoxMachine(ComObjPtr<VirtualSystemDescription> &vsdescThis,
|
---|
163 | ComPtr<IMachine> &pNewMachine,
|
---|
164 | ImportStack &stack);
|
---|
165 |
|
---|
166 | HRESULT importS3(TaskOVF *pTask);
|
---|
167 |
|
---|
168 | HRESULT writeImpl(OVFFormat aFormat, const LocationInfo &aLocInfo, ComObjPtr<Progress> &aProgress);
|
---|
169 |
|
---|
170 | struct XMLStack;
|
---|
171 | void buildXMLForOneVirtualSystem(xml::ElementNode &elmToAddVirtualSystemsTo,
|
---|
172 | std::list<xml::ElementNode*> *pllElementsWithUuidAttributes,
|
---|
173 | ComObjPtr<VirtualSystemDescription> &vsdescThis,
|
---|
174 | OVFFormat enFormat,
|
---|
175 | XMLStack &stack);
|
---|
176 |
|
---|
177 | HRESULT writeFS(const LocationInfo &locInfo, const OVFFormat enFormat, ComObjPtr<Progress> &pProgress);
|
---|
178 | HRESULT writeS3(TaskOVF *pTask);
|
---|
179 |
|
---|
180 | friend class Machine;
|
---|
181 | };
|
---|
182 |
|
---|
183 | struct VirtualSystemDescriptionEntry
|
---|
184 | {
|
---|
185 | uint32_t ulIndex; // zero-based index of this entry within array
|
---|
186 | VirtualSystemDescriptionType_T type; // type of this entry
|
---|
187 | Utf8Str strRef; // reference number (hard disk controllers only)
|
---|
188 | Utf8Str strOvf; // original OVF value (type-dependent)
|
---|
189 | Utf8Str strVboxSuggested; // configuration value (type-dependent); original value suggested by interpret()
|
---|
190 | Utf8Str strVboxCurrent; // configuration value (type-dependent); current value, either from interpret() or setFinalValue()
|
---|
191 | Utf8Str strExtraConfigSuggested; // extra configuration key=value strings (type-dependent); original value suggested by interpret()
|
---|
192 | Utf8Str strExtraConfigCurrent; // extra configuration key=value strings (type-dependent); current value, either from interpret() or setFinalValue()
|
---|
193 |
|
---|
194 | uint32_t ulSizeMB; // hard disk images only: a copy of ovf::DiskImage::ulSuggestedSizeMB
|
---|
195 | };
|
---|
196 |
|
---|
197 | class ATL_NO_VTABLE VirtualSystemDescription :
|
---|
198 | public VirtualBoxBase,
|
---|
199 | VBOX_SCRIPTABLE_IMPL(IVirtualSystemDescription)
|
---|
200 | {
|
---|
201 | friend class Appliance;
|
---|
202 |
|
---|
203 | public:
|
---|
204 | VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(VirtualSystemDescription, IVirtualSystemDescription)
|
---|
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 | /* IVirtualSystemDescription properties */
|
---|
226 | STDMETHOD(COMGETTER(Count))(ULONG *aCount);
|
---|
227 |
|
---|
228 | /* IVirtualSystemDescription methods */
|
---|
229 | STDMETHOD(GetDescription)(ComSafeArrayOut(VirtualSystemDescriptionType_T, aTypes),
|
---|
230 | ComSafeArrayOut(BSTR, aRefs),
|
---|
231 | ComSafeArrayOut(BSTR, aOvfValues),
|
---|
232 | ComSafeArrayOut(BSTR, aVboxValues),
|
---|
233 | ComSafeArrayOut(BSTR, aExtraConfigValues));
|
---|
234 |
|
---|
235 | STDMETHOD(GetDescriptionByType)(VirtualSystemDescriptionType_T aType,
|
---|
236 | ComSafeArrayOut(VirtualSystemDescriptionType_T, aTypes),
|
---|
237 | ComSafeArrayOut(BSTR, aRefs),
|
---|
238 | ComSafeArrayOut(BSTR, aOvfValues),
|
---|
239 | ComSafeArrayOut(BSTR, aVboxValues),
|
---|
240 | ComSafeArrayOut(BSTR, aExtraConfigValues));
|
---|
241 |
|
---|
242 | STDMETHOD(GetValuesByType)(VirtualSystemDescriptionType_T aType,
|
---|
243 | VirtualSystemDescriptionValueType_T aWhich,
|
---|
244 | ComSafeArrayOut(BSTR, aValues));
|
---|
245 |
|
---|
246 | STDMETHOD(SetFinalValues)(ComSafeArrayIn(BOOL, aEnabled),
|
---|
247 | ComSafeArrayIn(IN_BSTR, aVboxValues),
|
---|
248 | ComSafeArrayIn(IN_BSTR, aExtraConfigValues));
|
---|
249 |
|
---|
250 | STDMETHOD(AddDescription)(VirtualSystemDescriptionType_T aType,
|
---|
251 | IN_BSTR aVboxValue,
|
---|
252 | IN_BSTR aExtraConfigValue);
|
---|
253 |
|
---|
254 | /* public methods only for internal purposes */
|
---|
255 |
|
---|
256 | void addEntry(VirtualSystemDescriptionType_T aType,
|
---|
257 | const Utf8Str &strRef,
|
---|
258 | const Utf8Str &aOvfValue,
|
---|
259 | const Utf8Str &aVboxValue,
|
---|
260 | uint32_t ulSizeMB = 0,
|
---|
261 | const Utf8Str &strExtraConfig = "");
|
---|
262 |
|
---|
263 | std::list<VirtualSystemDescriptionEntry*> findByType(VirtualSystemDescriptionType_T aType);
|
---|
264 | const VirtualSystemDescriptionEntry* findControllerFromID(uint32_t id);
|
---|
265 |
|
---|
266 | void importVboxMachineXML(const xml::ElementNode &elmMachine);
|
---|
267 | const settings::MachineConfigFile* getMachineConfig() const;
|
---|
268 |
|
---|
269 | /* private instance data */
|
---|
270 | private:
|
---|
271 | struct Data;
|
---|
272 | Data *m;
|
---|
273 |
|
---|
274 | friend class Machine;
|
---|
275 | };
|
---|
276 |
|
---|
277 | #endif // ____H_APPLIANCEIMPL
|
---|
278 | /* vi: set tabstop=4 shiftwidth=4 expandtab: */
|
---|