1 | /* $Id: ApplianceImpl.h 27908 2010-03-31 14:32:46Z 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 */
|
---|
31 | class Progress;
|
---|
32 | class VirtualSystemDescription;
|
---|
33 |
|
---|
34 | namespace ovf
|
---|
35 | {
|
---|
36 | struct HardDiskController;
|
---|
37 | class OVFReader;
|
---|
38 | }
|
---|
39 |
|
---|
40 | namespace xml
|
---|
41 | {
|
---|
42 | class ElementNode;
|
---|
43 | }
|
---|
44 |
|
---|
45 | class ATL_NO_VTABLE Appliance :
|
---|
46 | public VirtualBoxBase,
|
---|
47 | public VirtualBoxSupportErrorInfoImpl<Appliance, IAppliance>,
|
---|
48 | public VirtualBoxSupportTranslation<Appliance>,
|
---|
49 | VBOX_SCRIPTABLE_IMPL(IAppliance)
|
---|
50 | {
|
---|
51 | public:
|
---|
52 | VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT (Appliance)
|
---|
53 |
|
---|
54 | DECLARE_NOT_AGGREGATABLE(Appliance)
|
---|
55 |
|
---|
56 | DECLARE_PROTECT_FINAL_CONSTRUCT()
|
---|
57 |
|
---|
58 | BEGIN_COM_MAP(Appliance)
|
---|
59 | COM_INTERFACE_ENTRY(ISupportErrorInfo)
|
---|
60 | COM_INTERFACE_ENTRY(IAppliance)
|
---|
61 | COM_INTERFACE_ENTRY(IDispatch)
|
---|
62 | END_COM_MAP()
|
---|
63 |
|
---|
64 | DECLARE_EMPTY_CTOR_DTOR (Appliance)
|
---|
65 |
|
---|
66 | enum OVFFormat
|
---|
67 | {
|
---|
68 | unspecified,
|
---|
69 | OVF_0_9,
|
---|
70 | OVF_1_0
|
---|
71 | };
|
---|
72 |
|
---|
73 | // public initializer/uninitializer for internal purposes only
|
---|
74 | HRESULT FinalConstruct() { return S_OK; }
|
---|
75 | void FinalRelease() { uninit(); }
|
---|
76 |
|
---|
77 | HRESULT init(VirtualBox *aVirtualBox);
|
---|
78 | void uninit();
|
---|
79 |
|
---|
80 | // for VirtualBoxSupportErrorInfoImpl
|
---|
81 | static const wchar_t *getComponentName() { return L"Appliance"; }
|
---|
82 |
|
---|
83 | /* IAppliance properties */
|
---|
84 | STDMETHOD(COMGETTER(Path))(BSTR *aPath);
|
---|
85 | STDMETHOD(COMGETTER(Disks))(ComSafeArrayOut(BSTR, aDisks));
|
---|
86 | STDMETHOD(COMGETTER(VirtualSystemDescriptions))(ComSafeArrayOut(IVirtualSystemDescription*, aVirtualSystemDescriptions));
|
---|
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 | /* private instance data */
|
---|
102 | private:
|
---|
103 | /** weak VirtualBox parent */
|
---|
104 | VirtualBox* const mVirtualBox;
|
---|
105 |
|
---|
106 | struct Data; // opaque, defined in ApplianceImpl.cpp
|
---|
107 | Data *m;
|
---|
108 |
|
---|
109 | bool isApplianceIdle() const;
|
---|
110 |
|
---|
111 | HRESULT searchUniqueVMName(Utf8Str& aName) const;
|
---|
112 | HRESULT searchUniqueDiskImageFilePath(Utf8Str& aName) const;
|
---|
113 | void waitForAsyncProgress(ComObjPtr<Progress> &pProgressThis, ComPtr<IProgress> &pProgressAsync);
|
---|
114 | void addWarning(const char* aWarning, ...);
|
---|
115 |
|
---|
116 | void disksWeight(uint32_t &ulTotalMB, uint32_t &cDisks) const;
|
---|
117 | HRESULT setUpProgressFS(ComObjPtr<Progress> &pProgress, const Bstr &bstrDescription);
|
---|
118 | HRESULT setUpProgressImportS3(ComObjPtr<Progress> &pProgress, const Bstr &bstrDescription);
|
---|
119 | HRESULT setUpProgressWriteS3(ComObjPtr<Progress> &pProgress, const Bstr &bstrDescription);
|
---|
120 |
|
---|
121 | struct LocationInfo;
|
---|
122 | void parseURI(Utf8Str strUri, LocationInfo &locInfo) const;
|
---|
123 | void parseBucket(Utf8Str &aPath, Utf8Str &aBucket) const;
|
---|
124 | Utf8Str manifestFileName(Utf8Str aPath) const;
|
---|
125 |
|
---|
126 | HRESULT readImpl(const LocationInfo &aLocInfo, ComObjPtr<Progress> &aProgress);
|
---|
127 |
|
---|
128 | struct TaskOVF;
|
---|
129 | static DECLCALLBACK(int) taskThreadImportOrExport(RTTHREAD aThread, void *pvUser);
|
---|
130 |
|
---|
131 | HRESULT readFS(const LocationInfo &locInfo);
|
---|
132 | HRESULT readS3(TaskOVF *pTask);
|
---|
133 |
|
---|
134 | void convertDiskAttachmentValues(const ovf::HardDiskController &hdc,
|
---|
135 | uint32_t ulAddressOnParent,
|
---|
136 | Bstr &controllerType,
|
---|
137 | int32_t &lChannel,
|
---|
138 | int32_t &lDevice);
|
---|
139 |
|
---|
140 | HRESULT importImpl(const LocationInfo &aLocInfo, ComObjPtr<Progress> &aProgress);
|
---|
141 |
|
---|
142 | HRESULT importFS(const LocationInfo &locInfo, ComObjPtr<Progress> &aProgress);
|
---|
143 | HRESULT importS3(TaskOVF *pTask);
|
---|
144 |
|
---|
145 | HRESULT writeImpl(OVFFormat aFormat, const LocationInfo &aLocInfo, ComObjPtr<Progress> &aProgress);
|
---|
146 |
|
---|
147 | struct XMLStack;
|
---|
148 | void buildXMLForOneVirtualSystem(xml::ElementNode &elmToAddVirtualSystemsTo,
|
---|
149 | ComObjPtr<VirtualSystemDescription> &vsdescThis,
|
---|
150 | OVFFormat enFormat,
|
---|
151 | XMLStack &stack);
|
---|
152 |
|
---|
153 | HRESULT writeFS(const LocationInfo &locInfo, const OVFFormat enFormat, ComObjPtr<Progress> &pProgress);
|
---|
154 | HRESULT writeS3(TaskOVF *pTask);
|
---|
155 |
|
---|
156 | friend class Machine;
|
---|
157 | };
|
---|
158 |
|
---|
159 | struct VirtualSystemDescriptionEntry
|
---|
160 | {
|
---|
161 | uint32_t ulIndex; // zero-based index of this entry within array
|
---|
162 | VirtualSystemDescriptionType_T type; // type of this entry
|
---|
163 | Utf8Str strRef; // reference number (hard disk controllers only)
|
---|
164 | Utf8Str strOvf; // original OVF value (type-dependent)
|
---|
165 | Utf8Str strVbox; // configuration value (type-dependent)
|
---|
166 | Utf8Str strExtraConfig; // extra configuration key=value strings (type-dependent)
|
---|
167 |
|
---|
168 | uint32_t ulSizeMB; // hard disk images only: size of the uncompressed image in MB
|
---|
169 | };
|
---|
170 |
|
---|
171 | class ATL_NO_VTABLE VirtualSystemDescription :
|
---|
172 | public VirtualBoxBase,
|
---|
173 | public VirtualBoxSupportErrorInfoImpl<VirtualSystemDescription, IVirtualSystemDescription>,
|
---|
174 | public VirtualBoxSupportTranslation<VirtualSystemDescription>,
|
---|
175 | VBOX_SCRIPTABLE_IMPL(IVirtualSystemDescription)
|
---|
176 | {
|
---|
177 | friend class Appliance;
|
---|
178 |
|
---|
179 | public:
|
---|
180 | VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT (VirtualSystemDescription)
|
---|
181 |
|
---|
182 | DECLARE_NOT_AGGREGATABLE(VirtualSystemDescription)
|
---|
183 |
|
---|
184 | DECLARE_PROTECT_FINAL_CONSTRUCT()
|
---|
185 |
|
---|
186 | BEGIN_COM_MAP(VirtualSystemDescription)
|
---|
187 | COM_INTERFACE_ENTRY(ISupportErrorInfo)
|
---|
188 | COM_INTERFACE_ENTRY(IVirtualSystemDescription)
|
---|
189 | COM_INTERFACE_ENTRY(IDispatch)
|
---|
190 | END_COM_MAP()
|
---|
191 |
|
---|
192 | DECLARE_EMPTY_CTOR_DTOR (VirtualSystemDescription)
|
---|
193 |
|
---|
194 | // public initializer/uninitializer for internal purposes only
|
---|
195 | HRESULT FinalConstruct() { return S_OK; }
|
---|
196 | void FinalRelease() { uninit(); }
|
---|
197 |
|
---|
198 | HRESULT init();
|
---|
199 | void uninit();
|
---|
200 |
|
---|
201 | // for VirtualBoxSupportErrorInfoImpl
|
---|
202 | static const wchar_t *getComponentName() { return L"VirtualSystemDescription"; }
|
---|
203 |
|
---|
204 | /* IVirtualSystemDescription properties */
|
---|
205 | STDMETHOD(COMGETTER(Count))(ULONG *aCount);
|
---|
206 |
|
---|
207 | /* IVirtualSystemDescription methods */
|
---|
208 | STDMETHOD(GetDescription)(ComSafeArrayOut(VirtualSystemDescriptionType_T, aTypes),
|
---|
209 | ComSafeArrayOut(BSTR, aRefs),
|
---|
210 | ComSafeArrayOut(BSTR, aOvfValues),
|
---|
211 | ComSafeArrayOut(BSTR, aVboxValues),
|
---|
212 | ComSafeArrayOut(BSTR, aExtraConfigValues));
|
---|
213 |
|
---|
214 | STDMETHOD(GetDescriptionByType)(VirtualSystemDescriptionType_T aType,
|
---|
215 | ComSafeArrayOut(VirtualSystemDescriptionType_T, aTypes),
|
---|
216 | ComSafeArrayOut(BSTR, aRefs),
|
---|
217 | ComSafeArrayOut(BSTR, aOvfValues),
|
---|
218 | ComSafeArrayOut(BSTR, aVboxValues),
|
---|
219 | ComSafeArrayOut(BSTR, aExtraConfigValues));
|
---|
220 |
|
---|
221 | STDMETHOD(GetValuesByType)(VirtualSystemDescriptionType_T aType,
|
---|
222 | VirtualSystemDescriptionValueType_T aWhich,
|
---|
223 | ComSafeArrayOut(BSTR, aValues));
|
---|
224 |
|
---|
225 | STDMETHOD(SetFinalValues)(ComSafeArrayIn(BOOL, aEnabled),
|
---|
226 | ComSafeArrayIn(IN_BSTR, aVboxValues),
|
---|
227 | ComSafeArrayIn(IN_BSTR, aExtraConfigValues));
|
---|
228 |
|
---|
229 | STDMETHOD(AddDescription)(VirtualSystemDescriptionType_T aType,
|
---|
230 | IN_BSTR aVboxValue,
|
---|
231 | IN_BSTR aExtraConfigValue);
|
---|
232 |
|
---|
233 | /* public methods only for internal purposes */
|
---|
234 |
|
---|
235 | void addEntry(VirtualSystemDescriptionType_T aType,
|
---|
236 | const Utf8Str &strRef,
|
---|
237 | const Utf8Str &aOrigValue,
|
---|
238 | const Utf8Str &aAutoValue,
|
---|
239 | uint32_t ulSizeMB = 0,
|
---|
240 | const Utf8Str &strExtraConfig = "");
|
---|
241 |
|
---|
242 | std::list<VirtualSystemDescriptionEntry*> findByType(VirtualSystemDescriptionType_T aType);
|
---|
243 | const VirtualSystemDescriptionEntry* findControllerFromID(uint32_t id);
|
---|
244 |
|
---|
245 | /* private instance data */
|
---|
246 | private:
|
---|
247 | struct Data;
|
---|
248 | Data *m;
|
---|
249 |
|
---|
250 | friend class Machine;
|
---|
251 | };
|
---|
252 |
|
---|
253 | #endif // ____H_APPLIANCEIMPL
|
---|
254 | /* vi: set tabstop=4 shiftwidth=4 expandtab: */
|
---|