1 | /* $Id: ApplianceImpl.h 28800 2010-04-27 08:22:32Z 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 { Regular, ImportS3, 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 &lChannel,
|
---|
144 | int32_t &lDevice);
|
---|
145 |
|
---|
146 | HRESULT importImpl(const LocationInfo &aLocInfo, ComObjPtr<Progress> &aProgress);
|
---|
147 | HRESULT manifestVerify(const LocationInfo &locInfo, const ovf::OVFReader &reader);
|
---|
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 | ComObjPtr<VirtualSystemDescription> &vsdescThis,
|
---|
171 | OVFFormat enFormat,
|
---|
172 | XMLStack &stack);
|
---|
173 |
|
---|
174 | HRESULT writeFS(const LocationInfo &locInfo, const OVFFormat enFormat, ComObjPtr<Progress> &pProgress);
|
---|
175 | HRESULT writeS3(TaskOVF *pTask);
|
---|
176 |
|
---|
177 | friend class Machine;
|
---|
178 | };
|
---|
179 |
|
---|
180 | struct VirtualSystemDescriptionEntry
|
---|
181 | {
|
---|
182 | uint32_t ulIndex; // zero-based index of this entry within array
|
---|
183 | VirtualSystemDescriptionType_T type; // type of this entry
|
---|
184 | Utf8Str strRef; // reference number (hard disk controllers only)
|
---|
185 | Utf8Str strOvf; // original OVF value (type-dependent)
|
---|
186 | Utf8Str strVbox; // configuration value (type-dependent)
|
---|
187 | Utf8Str strExtraConfig; // extra configuration key=value strings (type-dependent)
|
---|
188 |
|
---|
189 | uint32_t ulSizeMB; // hard disk images only: a copy of ovf::DiskImage::ulSuggestedSizeMB
|
---|
190 | };
|
---|
191 |
|
---|
192 | class ATL_NO_VTABLE VirtualSystemDescription :
|
---|
193 | public VirtualBoxBase,
|
---|
194 | public VirtualBoxSupportErrorInfoImpl<VirtualSystemDescription, IVirtualSystemDescription>,
|
---|
195 | public VirtualBoxSupportTranslation<VirtualSystemDescription>,
|
---|
196 | VBOX_SCRIPTABLE_IMPL(IVirtualSystemDescription)
|
---|
197 | {
|
---|
198 | friend class Appliance;
|
---|
199 |
|
---|
200 | public:
|
---|
201 | VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT (VirtualSystemDescription)
|
---|
202 |
|
---|
203 | DECLARE_NOT_AGGREGATABLE(VirtualSystemDescription)
|
---|
204 |
|
---|
205 | DECLARE_PROTECT_FINAL_CONSTRUCT()
|
---|
206 |
|
---|
207 | BEGIN_COM_MAP(VirtualSystemDescription)
|
---|
208 | COM_INTERFACE_ENTRY(ISupportErrorInfo)
|
---|
209 | COM_INTERFACE_ENTRY(IVirtualSystemDescription)
|
---|
210 | COM_INTERFACE_ENTRY(IDispatch)
|
---|
211 | END_COM_MAP()
|
---|
212 |
|
---|
213 | DECLARE_EMPTY_CTOR_DTOR (VirtualSystemDescription)
|
---|
214 |
|
---|
215 | // public initializer/uninitializer for internal purposes only
|
---|
216 | HRESULT FinalConstruct() { return S_OK; }
|
---|
217 | void FinalRelease() { uninit(); }
|
---|
218 |
|
---|
219 | HRESULT init();
|
---|
220 | void uninit();
|
---|
221 |
|
---|
222 | // for VirtualBoxSupportErrorInfoImpl
|
---|
223 | static const wchar_t *getComponentName() { return L"VirtualSystemDescription"; }
|
---|
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: */
|
---|