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