1 | /* $Id: MediumImpl.h 27831 2010-03-30 14:55:27Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | *
|
---|
4 | * VirtualBox COM class implementation
|
---|
5 | */
|
---|
6 |
|
---|
7 | /*
|
---|
8 | * Copyright (C) 2008-2010 Sun Microsystems, Inc.
|
---|
9 | *
|
---|
10 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
11 | * available from http://www.virtualbox.org. This file is free software;
|
---|
12 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
13 | * General Public License (GPL) as published by the Free Software
|
---|
14 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
15 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
16 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
17 | *
|
---|
18 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
19 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
20 | * additional information or have any questions.
|
---|
21 | */
|
---|
22 |
|
---|
23 | #ifndef ____H_MEDIUMIMPL
|
---|
24 | #define ____H_MEDIUMIMPL
|
---|
25 |
|
---|
26 | #include "VirtualBoxBase.h"
|
---|
27 |
|
---|
28 | class Progress;
|
---|
29 |
|
---|
30 | namespace settings
|
---|
31 | {
|
---|
32 | struct Medium;
|
---|
33 | }
|
---|
34 |
|
---|
35 | ////////////////////////////////////////////////////////////////////////////////
|
---|
36 |
|
---|
37 | /**
|
---|
38 | * Medium component class for all media types.
|
---|
39 | */
|
---|
40 | class ATL_NO_VTABLE Medium :
|
---|
41 | public VirtualBoxBase,
|
---|
42 | public com::SupportErrorInfoImpl<Medium, IMedium>,
|
---|
43 | public VirtualBoxSupportTranslation<Medium>,
|
---|
44 | VBOX_SCRIPTABLE_IMPL(IMedium)
|
---|
45 | {
|
---|
46 | public:
|
---|
47 | class MergeChain;
|
---|
48 | class ImageChain;
|
---|
49 |
|
---|
50 | VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(Medium)
|
---|
51 |
|
---|
52 | DECLARE_NOT_AGGREGATABLE(Medium)
|
---|
53 |
|
---|
54 | DECLARE_PROTECT_FINAL_CONSTRUCT()
|
---|
55 |
|
---|
56 | BEGIN_COM_MAP(Medium)
|
---|
57 | COM_INTERFACE_ENTRY(ISupportErrorInfo)
|
---|
58 | COM_INTERFACE_ENTRY(IMedium)
|
---|
59 | COM_INTERFACE_ENTRY(IDispatch)
|
---|
60 | END_COM_MAP()
|
---|
61 |
|
---|
62 | DECLARE_EMPTY_CTOR_DTOR(Medium)
|
---|
63 |
|
---|
64 | HRESULT FinalConstruct();
|
---|
65 | void FinalRelease();
|
---|
66 |
|
---|
67 | enum HDDOpenMode { OpenReadWrite, OpenReadOnly };
|
---|
68 | // have to use a special enum for the overloaded init() below;
|
---|
69 | // can't use AccessMode_T from XIDL because that's mapped to an int
|
---|
70 | // and would be ambiguous
|
---|
71 |
|
---|
72 | // public initializer/uninitializer for internal purposes only
|
---|
73 | HRESULT init(VirtualBox *aVirtualBox,
|
---|
74 | CBSTR aFormat,
|
---|
75 | CBSTR aLocation,
|
---|
76 | bool *pfNeedsSaveSettings);
|
---|
77 | HRESULT init(VirtualBox *aVirtualBox,
|
---|
78 | CBSTR aLocation,
|
---|
79 | HDDOpenMode enOpenMode,
|
---|
80 | DeviceType_T aDeviceType,
|
---|
81 | BOOL aSetImageId,
|
---|
82 | const Guid &aImageId,
|
---|
83 | BOOL aSetParentId,
|
---|
84 | const Guid &aParentId);
|
---|
85 | // initializer used when loading settings
|
---|
86 | HRESULT init(VirtualBox *aVirtualBox,
|
---|
87 | Medium *aParent,
|
---|
88 | DeviceType_T aDeviceType,
|
---|
89 | const settings::Medium &data);
|
---|
90 | // initializer for host floppy/DVD
|
---|
91 | HRESULT init(VirtualBox *aVirtualBox,
|
---|
92 | DeviceType_T aDeviceType,
|
---|
93 | CBSTR aLocation,
|
---|
94 | CBSTR aDescription = NULL);
|
---|
95 | void uninit();
|
---|
96 |
|
---|
97 | void deparent();
|
---|
98 |
|
---|
99 | // IMedium properties
|
---|
100 | STDMETHOD(COMGETTER(Id))(BSTR *aId);
|
---|
101 | STDMETHOD(COMGETTER(Description))(BSTR *aDescription);
|
---|
102 | STDMETHOD(COMSETTER(Description))(IN_BSTR aDescription);
|
---|
103 | STDMETHOD(COMGETTER(State))(MediumState_T *aState);
|
---|
104 | STDMETHOD(COMGETTER(Location))(BSTR *aLocation);
|
---|
105 | STDMETHOD(COMSETTER(Location))(IN_BSTR aLocation);
|
---|
106 | STDMETHOD(COMGETTER(Name))(BSTR *aName);
|
---|
107 | STDMETHOD(COMGETTER(DeviceType))(DeviceType_T *aDeviceType);
|
---|
108 | STDMETHOD(COMGETTER(HostDrive))(BOOL *aHostDrive);
|
---|
109 | STDMETHOD(COMGETTER(Size))(ULONG64 *aSize);
|
---|
110 | STDMETHOD(COMGETTER(Format))(BSTR *aFormat);
|
---|
111 | STDMETHOD(COMGETTER(Type))(MediumType_T *aType);
|
---|
112 | STDMETHOD(COMSETTER(Type))(MediumType_T aType);
|
---|
113 | STDMETHOD(COMGETTER(Parent))(IMedium **aParent);
|
---|
114 | STDMETHOD(COMGETTER(Children))(ComSafeArrayOut(IMedium *, aChildren));
|
---|
115 | STDMETHOD(COMGETTER(Base))(IMedium **aBase);
|
---|
116 | STDMETHOD(COMGETTER(ReadOnly))(BOOL *aReadOnly);
|
---|
117 | STDMETHOD(COMGETTER(LogicalSize))(ULONG64 *aLogicalSize);
|
---|
118 | STDMETHOD(COMGETTER(AutoReset))(BOOL *aAutoReset);
|
---|
119 | STDMETHOD(COMSETTER(AutoReset))(BOOL aAutoReset);
|
---|
120 | STDMETHOD(COMGETTER(LastAccessError))(BSTR *aLastAccessError);
|
---|
121 | STDMETHOD(COMGETTER(MachineIds))(ComSafeArrayOut(BSTR, aMachineIds));
|
---|
122 |
|
---|
123 | // IMedium methods
|
---|
124 | STDMETHOD(RefreshState)(MediumState_T *aState);
|
---|
125 | STDMETHOD(GetSnapshotIds)(IN_BSTR aMachineId,
|
---|
126 | ComSafeArrayOut(BSTR, aSnapshotIds));
|
---|
127 | STDMETHOD(LockRead)(MediumState_T *aState);
|
---|
128 | STDMETHOD(UnlockRead)(MediumState_T *aState);
|
---|
129 | STDMETHOD(LockWrite)(MediumState_T *aState);
|
---|
130 | STDMETHOD(UnlockWrite)(MediumState_T *aState);
|
---|
131 | STDMETHOD(Close)();
|
---|
132 | STDMETHOD(GetProperty)(IN_BSTR aName, BSTR *aValue);
|
---|
133 | STDMETHOD(SetProperty)(IN_BSTR aName, IN_BSTR aValue);
|
---|
134 | STDMETHOD(GetProperties)(IN_BSTR aNames,
|
---|
135 | ComSafeArrayOut(BSTR, aReturnNames),
|
---|
136 | ComSafeArrayOut(BSTR, aReturnValues));
|
---|
137 | STDMETHOD(SetProperties)(ComSafeArrayIn(IN_BSTR, aNames),
|
---|
138 | ComSafeArrayIn(IN_BSTR, aValues));
|
---|
139 | STDMETHOD(CreateBaseStorage)(ULONG64 aLogicalSize,
|
---|
140 | MediumVariant_T aVariant,
|
---|
141 | IProgress **aProgress);
|
---|
142 | STDMETHOD(DeleteStorage)(IProgress **aProgress);
|
---|
143 | STDMETHOD(CreateDiffStorage)(IMedium *aTarget,
|
---|
144 | MediumVariant_T aVariant,
|
---|
145 | IProgress **aProgress);
|
---|
146 | STDMETHOD(MergeTo)(IN_BSTR aTargetId, IProgress **aProgress);
|
---|
147 | STDMETHOD(CloneTo)(IMedium *aTarget, MediumVariant_T aVariant,
|
---|
148 | IMedium *aParent, IProgress **aProgress);
|
---|
149 | STDMETHOD(Compact)(IProgress **aProgress);
|
---|
150 | STDMETHOD(Resize)(ULONG64 aLogicalSize, IProgress **aProgress);
|
---|
151 | STDMETHOD(Reset)(IProgress **aProgress);
|
---|
152 |
|
---|
153 | // public methods for internal purposes only
|
---|
154 | const ComObjPtr<Medium>& getParent() const;
|
---|
155 | const MediaList& getChildren() const;
|
---|
156 |
|
---|
157 | const Guid& getId() const;
|
---|
158 | MediumState_T getState() const;
|
---|
159 | const Utf8Str& getLocation() const;
|
---|
160 | const Utf8Str& getLocationFull() const;
|
---|
161 | uint64_t getSize() const;
|
---|
162 |
|
---|
163 | HRESULT attachTo(const Guid &aMachineId,
|
---|
164 | const Guid &aSnapshotId = Guid::Empty);
|
---|
165 | HRESULT detachFrom(const Guid &aMachineId,
|
---|
166 | const Guid &aSnapshotId = Guid::Empty);
|
---|
167 |
|
---|
168 | const Guid* getFirstMachineBackrefId() const;
|
---|
169 | const Guid* getFirstMachineBackrefSnapshotId() const;
|
---|
170 |
|
---|
171 | #ifdef DEBUG
|
---|
172 | void dumpBackRefs();
|
---|
173 | #endif
|
---|
174 |
|
---|
175 | HRESULT updatePath(const char *aOldPath, const char *aNewPath);
|
---|
176 | void updatePaths(const char *aOldPath, const char *aNewPath);
|
---|
177 |
|
---|
178 | ComObjPtr<Medium> getBase(uint32_t *aLevel = NULL);
|
---|
179 |
|
---|
180 | bool isReadOnly();
|
---|
181 |
|
---|
182 | HRESULT saveSettings(settings::Medium &data);
|
---|
183 |
|
---|
184 | HRESULT compareLocationTo(const char *aLocation, int &aResult);
|
---|
185 |
|
---|
186 | /**
|
---|
187 | * Shortcut to #deleteStorage() that doesn't wait for operation completion
|
---|
188 | * and implies the progress object will be used for waiting.
|
---|
189 | */
|
---|
190 | HRESULT deleteStorageNoWait(ComObjPtr<Progress> &aProgress)
|
---|
191 | { return deleteStorage(&aProgress, false /* aWait */, NULL /* pfNeedsSaveSettings */); }
|
---|
192 |
|
---|
193 | /**
|
---|
194 | * Shortcut to #deleteStorage() that wait for operation completion by
|
---|
195 | * blocking the current thread.
|
---|
196 | */
|
---|
197 | HRESULT deleteStorageAndWait(ComObjPtr<Progress> *aProgress, bool *pfNeedsSaveSettings)
|
---|
198 | { return deleteStorage(aProgress, true /* aWait */, pfNeedsSaveSettings); }
|
---|
199 |
|
---|
200 | /**
|
---|
201 | * Shortcut to #createDiffStorage() that doesn't wait for operation
|
---|
202 | * completion and implies the progress object will be used for waiting.
|
---|
203 | */
|
---|
204 | HRESULT createDiffStorageNoWait(ComObjPtr<Medium> &aTarget,
|
---|
205 | MediumVariant_T aVariant,
|
---|
206 | ComObjPtr<Progress> &aProgress)
|
---|
207 | { return createDiffStorage(aTarget, aVariant, &aProgress, false /* aWait */, NULL /* pfNeedsSaveSettings*/ ); }
|
---|
208 |
|
---|
209 | /**
|
---|
210 | * Shortcut to #createDiffStorage() that wait for operation completion by
|
---|
211 | * blocking the current thread.
|
---|
212 | */
|
---|
213 | HRESULT createDiffStorageAndWait(ComObjPtr<Medium> &aTarget,
|
---|
214 | MediumVariant_T aVariant,
|
---|
215 | bool *pfNeedsSaveSettings)
|
---|
216 | { return createDiffStorage(aTarget, aVariant, NULL /*aProgress*/, true /* aWait */, pfNeedsSaveSettings); }
|
---|
217 |
|
---|
218 | HRESULT prepareMergeTo(Medium *aTarget, MergeChain * &aChain,
|
---|
219 | bool aIgnoreAttachments = false);
|
---|
220 |
|
---|
221 | /**
|
---|
222 | * Shortcut to #mergeTo() that doesn't wait for operation completion and
|
---|
223 | * implies the progress object will be used for waiting.
|
---|
224 | */
|
---|
225 | HRESULT mergeToNoWait(MergeChain *aChain,
|
---|
226 | ComObjPtr<Progress> &aProgress)
|
---|
227 | { return mergeTo(aChain, &aProgress, false /* aWait */, NULL /*pfNeedsSaveSettings*/); }
|
---|
228 |
|
---|
229 | /**
|
---|
230 | * Shortcut to #mergeTo() that wait for operation completion by
|
---|
231 | * blocking the current thread.
|
---|
232 | */
|
---|
233 | HRESULT mergeToAndWait(MergeChain *aChain,
|
---|
234 | ComObjPtr<Progress> *aProgress,
|
---|
235 | bool *pfNeedsSaveSettings)
|
---|
236 | { return mergeTo(aChain, aProgress, true /* aWait */, pfNeedsSaveSettings); }
|
---|
237 |
|
---|
238 | void cancelMergeTo(MergeChain *aChain);
|
---|
239 |
|
---|
240 | Utf8Str getName();
|
---|
241 |
|
---|
242 | HRESULT prepareDiscard(MergeChain * &aChain);
|
---|
243 | HRESULT discard(ComObjPtr<Progress> &aProgress, ULONG ulWeight, MergeChain *aChain, bool *pfNeedsSaveSettings);
|
---|
244 | void cancelDiscard(MergeChain *aChain);
|
---|
245 |
|
---|
246 | /** Returns a preferred format for a differencing hard disk. */
|
---|
247 | Bstr preferredDiffFormat();
|
---|
248 |
|
---|
249 | // unsafe inline public methods for internal purposes only (ensure there is
|
---|
250 | // a caller and a read lock before calling them!)
|
---|
251 | MediumType_T getType() const;
|
---|
252 |
|
---|
253 | /** For com::SupportErrorInfoImpl. */
|
---|
254 | static const char *ComponentName() { return "Medium"; }
|
---|
255 |
|
---|
256 | private:
|
---|
257 |
|
---|
258 | HRESULT queryInfo();
|
---|
259 |
|
---|
260 | /**
|
---|
261 | * Performs extra checks if the medium can be closed and returns S_OK in
|
---|
262 | * this case. Otherwise, returns a respective error message. Called by
|
---|
263 | * Close() under the medium tree lock and the medium lock.
|
---|
264 | */
|
---|
265 | HRESULT canClose();
|
---|
266 |
|
---|
267 | /**
|
---|
268 | * Unregisters this medium with mVirtualBox. Called by Close() under
|
---|
269 | * the medium tree lock.
|
---|
270 | */
|
---|
271 | HRESULT unregisterWithVirtualBox(bool *pfNeedsSaveSettings);
|
---|
272 |
|
---|
273 | HRESULT setStateError();
|
---|
274 |
|
---|
275 | HRESULT deleteStorage(ComObjPtr<Progress> *aProgress, bool aWait, bool *pfNeedsSaveSettings);
|
---|
276 |
|
---|
277 | HRESULT createDiffStorage(ComObjPtr<Medium> &aTarget,
|
---|
278 | MediumVariant_T aVariant,
|
---|
279 | ComObjPtr<Progress> *aProgress,
|
---|
280 | bool aWait,
|
---|
281 | bool *pfNeedsSaveSettings);
|
---|
282 |
|
---|
283 | HRESULT mergeTo(MergeChain *aChain,
|
---|
284 | ComObjPtr<Progress> *aProgress,
|
---|
285 | bool aWait,
|
---|
286 | bool *pfNeedsSaveSettings);
|
---|
287 |
|
---|
288 | HRESULT setLocation(const Utf8Str &aLocation, const Utf8Str &aFormat = Utf8Str());
|
---|
289 | HRESULT setFormat(CBSTR aFormat);
|
---|
290 |
|
---|
291 | Utf8Str vdError(int aVRC);
|
---|
292 |
|
---|
293 | static DECLCALLBACK(void) vdErrorCall(void *pvUser, int rc, RT_SRC_POS_DECL,
|
---|
294 | const char *pszFormat, va_list va);
|
---|
295 |
|
---|
296 | static DECLCALLBACK(bool) vdConfigAreKeysValid(void *pvUser,
|
---|
297 | const char *pszzValid);
|
---|
298 | static DECLCALLBACK(int) vdConfigQuerySize(void *pvUser, const char *pszName,
|
---|
299 | size_t *pcbValue);
|
---|
300 | static DECLCALLBACK(int) vdConfigQuery(void *pvUser, const char *pszName,
|
---|
301 | char *pszValue, size_t cchValue);
|
---|
302 |
|
---|
303 | class Task;
|
---|
304 | class CreateBaseTask;
|
---|
305 | class CreateDiffTask;
|
---|
306 | class CloneTask;
|
---|
307 | class CompactTask;
|
---|
308 | class ResetTask;
|
---|
309 | class DeleteTask;
|
---|
310 | class MergeTask;
|
---|
311 | friend class Task;
|
---|
312 | friend class CreateBaseTask;
|
---|
313 | friend class CreateDiffTask;
|
---|
314 | friend class CloneTask;
|
---|
315 | friend class CompactTask;
|
---|
316 | friend class ResetTask;
|
---|
317 | friend class DeleteTask;
|
---|
318 | friend class MergeTask;
|
---|
319 |
|
---|
320 | HRESULT startThread(Medium::Task *pTask);
|
---|
321 | HRESULT runNow(Medium::Task *pTask, bool *pfNeedsSaveSettings);
|
---|
322 |
|
---|
323 | HRESULT taskThreadCreateBase(Medium::CreateBaseTask &task);
|
---|
324 | HRESULT taskThreadCreateDiff(Medium::CreateDiffTask &task);
|
---|
325 | HRESULT taskThreadMerge(Medium::MergeTask &task);
|
---|
326 | HRESULT taskThreadClone(Medium::CloneTask &task);
|
---|
327 | HRESULT taskThreadDelete(Medium::DeleteTask &task);
|
---|
328 | HRESULT taskThreadReset(Medium::ResetTask &task);
|
---|
329 | HRESULT taskThreadCompact(Medium::CompactTask &task);
|
---|
330 |
|
---|
331 | struct Data; // opaque data struct, defined in MediumImpl.cpp
|
---|
332 | Data *m;
|
---|
333 | };
|
---|
334 |
|
---|
335 | #endif /* ____H_MEDIUMIMPL */
|
---|
336 |
|
---|