VirtualBox

source: vbox/trunk/src/VBox/Main/include/ApplianceImpl.h@ 30764

Last change on this file since 30764 was 30764, checked in by vboxsync, 15 years ago

back out r63543, r63544 until windows build problems can be solved properly

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette