VirtualBox

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

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

Main: more Machine::init() work to get OVF vbox:Machine import running; works now for machines without media attachments

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.7 KB
Line 
1/* $Id: ApplianceImpl.h 28110 2010-04-08 18:07:13Z vboxsync $ */
2
3/** @file
4 *
5 * VirtualBox COM class implementation
6 */
7
8/*
9 * Copyright (C) 2006-2009 Sun Microsystems, Inc.
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 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
20 * Clara, CA 95054 USA or visit http://www.sun.com if you need
21 * additional information or have any questions.
22 */
23
24#ifndef ____H_APPLIANCEIMPL
25#define ____H_APPLIANCEIMPL
26
27/* VBox includes */
28#include "VirtualBoxBase.h"
29
30/* VBox forward declarations */
31class Progress;
32class VirtualSystemDescription;
33
34namespace ovf
35{
36 struct HardDiskController;
37 struct VirtualSystem;
38 class OVFReader;
39}
40
41namespace xml
42{
43 class ElementNode;
44}
45
46namespace settings
47{
48 class MachineConfigFile;
49}
50
51class ATL_NO_VTABLE Appliance :
52 public VirtualBoxBase,
53 public VirtualBoxSupportErrorInfoImpl<Appliance, IAppliance>,
54 public VirtualBoxSupportTranslation<Appliance>,
55 VBOX_SCRIPTABLE_IMPL(IAppliance)
56{
57public:
58 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT (Appliance)
59
60 DECLARE_NOT_AGGREGATABLE(Appliance)
61
62 DECLARE_PROTECT_FINAL_CONSTRUCT()
63
64 BEGIN_COM_MAP(Appliance)
65 COM_INTERFACE_ENTRY(ISupportErrorInfo)
66 COM_INTERFACE_ENTRY(IAppliance)
67 COM_INTERFACE_ENTRY(IDispatch)
68 END_COM_MAP()
69
70 DECLARE_EMPTY_CTOR_DTOR (Appliance)
71
72 enum OVFFormat
73 {
74 unspecified,
75 OVF_0_9,
76 OVF_1_0
77 };
78
79 // public initializer/uninitializer for internal purposes only
80 HRESULT FinalConstruct() { return S_OK; }
81 void FinalRelease() { uninit(); }
82
83 HRESULT init(VirtualBox *aVirtualBox);
84 void uninit();
85
86 // for VirtualBoxSupportErrorInfoImpl
87 static const wchar_t *getComponentName() { return L"Appliance"; }
88
89 /* IAppliance properties */
90 STDMETHOD(COMGETTER(Path))(BSTR *aPath);
91 STDMETHOD(COMGETTER(Disks))(ComSafeArrayOut(BSTR, aDisks));
92 STDMETHOD(COMGETTER(VirtualSystemDescriptions))(ComSafeArrayOut(IVirtualSystemDescription*, aVirtualSystemDescriptions));
93
94 /* IAppliance methods */
95 /* Import methods */
96 STDMETHOD(Read)(IN_BSTR path, IProgress **aProgress);
97 STDMETHOD(Interpret)(void);
98 STDMETHOD(ImportMachines)(IProgress **aProgress);
99 /* Export methods */
100 STDMETHOD(CreateVFSExplorer)(IN_BSTR aURI, IVFSExplorer **aExplorer);
101 STDMETHOD(Write)(IN_BSTR format, IN_BSTR path, IProgress **aProgress);
102
103 STDMETHOD(GetWarnings)(ComSafeArrayOut(BSTR, aWarnings));
104
105 /* public methods only for internal purposes */
106
107 /* private instance data */
108private:
109 /** weak VirtualBox parent */
110 VirtualBox* const mVirtualBox;
111
112 struct Data; // opaque, defined in ApplianceImpl.cpp
113 Data *m;
114
115 bool isApplianceIdle() const;
116
117 HRESULT searchUniqueVMName(Utf8Str& aName) const;
118 HRESULT searchUniqueDiskImageFilePath(Utf8Str& aName) const;
119 void waitForAsyncProgress(ComObjPtr<Progress> &pProgressThis, ComPtr<IProgress> &pProgressAsync);
120 void addWarning(const char* aWarning, ...);
121
122 void disksWeight(uint32_t &ulTotalMB, uint32_t &cDisks) const;
123 HRESULT setUpProgressFS(ComObjPtr<Progress> &pProgress, const Bstr &bstrDescription);
124 HRESULT setUpProgressImportS3(ComObjPtr<Progress> &pProgress, const Bstr &bstrDescription);
125 HRESULT setUpProgressWriteS3(ComObjPtr<Progress> &pProgress, const Bstr &bstrDescription);
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
148 HRESULT importFS(const LocationInfo &locInfo, ComObjPtr<Progress> &aProgress);
149 struct ImportStack;
150 void importVBoxMachine(ComObjPtr<VirtualSystemDescription> &vsdescThis,
151 ComPtr<IMachine> &pNewMachine,
152 ImportStack &stack);
153 void importMachineGeneric(const ovf::VirtualSystem &vsysThis,
154 ComObjPtr<VirtualSystemDescription> &vsdescThis,
155 ComPtr<IMachine> &pNewMachine,
156 ImportStack &stack);
157 HRESULT importS3(TaskOVF *pTask);
158
159 HRESULT writeImpl(OVFFormat aFormat, const LocationInfo &aLocInfo, ComObjPtr<Progress> &aProgress);
160
161 struct XMLStack;
162 void buildXMLForOneVirtualSystem(xml::ElementNode &elmToAddVirtualSystemsTo,
163 ComObjPtr<VirtualSystemDescription> &vsdescThis,
164 OVFFormat enFormat,
165 XMLStack &stack);
166
167 HRESULT writeFS(const LocationInfo &locInfo, const OVFFormat enFormat, ComObjPtr<Progress> &pProgress);
168 HRESULT writeS3(TaskOVF *pTask);
169
170 friend class Machine;
171};
172
173struct VirtualSystemDescriptionEntry
174{
175 uint32_t ulIndex; // zero-based index of this entry within array
176 VirtualSystemDescriptionType_T type; // type of this entry
177 Utf8Str strRef; // reference number (hard disk controllers only)
178 Utf8Str strOvf; // original OVF value (type-dependent)
179 Utf8Str strVbox; // configuration value (type-dependent)
180 Utf8Str strExtraConfig; // extra configuration key=value strings (type-dependent)
181
182 uint32_t ulSizeMB; // hard disk images only: size of the uncompressed image in MB
183};
184
185class ATL_NO_VTABLE VirtualSystemDescription :
186 public VirtualBoxBase,
187 public VirtualBoxSupportErrorInfoImpl<VirtualSystemDescription, IVirtualSystemDescription>,
188 public VirtualBoxSupportTranslation<VirtualSystemDescription>,
189 VBOX_SCRIPTABLE_IMPL(IVirtualSystemDescription)
190{
191 friend class Appliance;
192
193public:
194 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT (VirtualSystemDescription)
195
196 DECLARE_NOT_AGGREGATABLE(VirtualSystemDescription)
197
198 DECLARE_PROTECT_FINAL_CONSTRUCT()
199
200 BEGIN_COM_MAP(VirtualSystemDescription)
201 COM_INTERFACE_ENTRY(ISupportErrorInfo)
202 COM_INTERFACE_ENTRY(IVirtualSystemDescription)
203 COM_INTERFACE_ENTRY(IDispatch)
204 END_COM_MAP()
205
206 DECLARE_EMPTY_CTOR_DTOR (VirtualSystemDescription)
207
208 // public initializer/uninitializer for internal purposes only
209 HRESULT FinalConstruct() { return S_OK; }
210 void FinalRelease() { uninit(); }
211
212 HRESULT init();
213 void uninit();
214
215 // for VirtualBoxSupportErrorInfoImpl
216 static const wchar_t *getComponentName() { return L"VirtualSystemDescription"; }
217
218 /* IVirtualSystemDescription properties */
219 STDMETHOD(COMGETTER(Count))(ULONG *aCount);
220
221 /* IVirtualSystemDescription methods */
222 STDMETHOD(GetDescription)(ComSafeArrayOut(VirtualSystemDescriptionType_T, aTypes),
223 ComSafeArrayOut(BSTR, aRefs),
224 ComSafeArrayOut(BSTR, aOvfValues),
225 ComSafeArrayOut(BSTR, aVboxValues),
226 ComSafeArrayOut(BSTR, aExtraConfigValues));
227
228 STDMETHOD(GetDescriptionByType)(VirtualSystemDescriptionType_T aType,
229 ComSafeArrayOut(VirtualSystemDescriptionType_T, aTypes),
230 ComSafeArrayOut(BSTR, aRefs),
231 ComSafeArrayOut(BSTR, aOvfValues),
232 ComSafeArrayOut(BSTR, aVboxValues),
233 ComSafeArrayOut(BSTR, aExtraConfigValues));
234
235 STDMETHOD(GetValuesByType)(VirtualSystemDescriptionType_T aType,
236 VirtualSystemDescriptionValueType_T aWhich,
237 ComSafeArrayOut(BSTR, aValues));
238
239 STDMETHOD(SetFinalValues)(ComSafeArrayIn(BOOL, aEnabled),
240 ComSafeArrayIn(IN_BSTR, aVboxValues),
241 ComSafeArrayIn(IN_BSTR, aExtraConfigValues));
242
243 STDMETHOD(AddDescription)(VirtualSystemDescriptionType_T aType,
244 IN_BSTR aVboxValue,
245 IN_BSTR aExtraConfigValue);
246
247 /* public methods only for internal purposes */
248
249 void addEntry(VirtualSystemDescriptionType_T aType,
250 const Utf8Str &strRef,
251 const Utf8Str &aOrigValue,
252 const Utf8Str &aAutoValue,
253 uint32_t ulSizeMB = 0,
254 const Utf8Str &strExtraConfig = "");
255
256 std::list<VirtualSystemDescriptionEntry*> findByType(VirtualSystemDescriptionType_T aType);
257 const VirtualSystemDescriptionEntry* findControllerFromID(uint32_t id);
258
259 void importVboxMachineXML(const xml::ElementNode &elmMachine);
260 const settings::MachineConfigFile* getMachineConfig() const;
261
262 /* private instance data */
263private:
264 struct Data;
265 Data *m;
266
267 friend class Machine;
268};
269
270#endif // ____H_APPLIANCEIMPL
271/* vi: set tabstop=4 shiftwidth=4 expandtab: */
Note: See TracBrowser for help on using the repository browser.

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