VirtualBox

source: vbox/trunk/src/VBox/Main/include/MediumImpl.h@ 28973

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

Main/Medium: new helper method for fixing up parent UUIDs of children moved around by merging, make diff reset rely on documented VBoxHDD behavior by opening the entire medium chain, minor bugfixing to get the reported image sizes in the GUI right, fixing the parameters of an error message to print the right image name

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.9 KB
Line 
1/* $Id: MediumImpl.h 28872 2010-04-28 14:54:03Z vboxsync $ */
2
3/** @file
4 *
5 * VirtualBox COM class implementation
6 */
7
8/*
9 * Copyright (C) 2008-2010 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_MEDIUMIMPL
21#define ____H_MEDIUMIMPL
22
23#include "VirtualBoxBase.h"
24#include "MediumLock.h"
25
26class Progress;
27
28namespace settings
29{
30 struct Medium;
31}
32
33////////////////////////////////////////////////////////////////////////////////
34
35/**
36 * Medium component class for all media types.
37 */
38class ATL_NO_VTABLE Medium :
39 public VirtualBoxBase,
40 public com::SupportErrorInfoImpl<Medium, IMedium>,
41 public VirtualBoxSupportTranslation<Medium>,
42 VBOX_SCRIPTABLE_IMPL(IMedium)
43{
44public:
45 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(Medium)
46
47 DECLARE_NOT_AGGREGATABLE(Medium)
48
49 DECLARE_PROTECT_FINAL_CONSTRUCT()
50
51 BEGIN_COM_MAP(Medium)
52 COM_INTERFACE_ENTRY(ISupportErrorInfo)
53 COM_INTERFACE_ENTRY(IMedium)
54 COM_INTERFACE_ENTRY(IDispatch)
55 END_COM_MAP()
56
57 DECLARE_EMPTY_CTOR_DTOR(Medium)
58
59 HRESULT FinalConstruct();
60 void FinalRelease();
61
62 enum HDDOpenMode { OpenReadWrite, OpenReadOnly };
63 // have to use a special enum for the overloaded init() below;
64 // can't use AccessMode_T from XIDL because that's mapped to an int
65 // and would be ambiguous
66
67 // public initializer/uninitializer for internal purposes only
68 HRESULT init(VirtualBox *aVirtualBox,
69 CBSTR aFormat,
70 CBSTR aLocation,
71 bool *pfNeedsSaveSettings);
72 HRESULT init(VirtualBox *aVirtualBox,
73 CBSTR aLocation,
74 HDDOpenMode enOpenMode,
75 DeviceType_T aDeviceType,
76 BOOL aSetImageId,
77 const Guid &aImageId,
78 BOOL aSetParentId,
79 const Guid &aParentId);
80 // initializer used when loading settings
81 HRESULT init(VirtualBox *aVirtualBox,
82 Medium *aParent,
83 DeviceType_T aDeviceType,
84 const settings::Medium &data);
85 // initializer for host floppy/DVD
86 HRESULT init(VirtualBox *aVirtualBox,
87 DeviceType_T aDeviceType,
88 CBSTR aLocation,
89 CBSTR aDescription = NULL);
90 void uninit();
91
92 void deparent();
93 void setParent(const ComObjPtr<Medium> &pParent);
94
95 // IMedium properties
96 STDMETHOD(COMGETTER(Id))(BSTR *aId);
97 STDMETHOD(COMGETTER(Description))(BSTR *aDescription);
98 STDMETHOD(COMSETTER(Description))(IN_BSTR aDescription);
99 STDMETHOD(COMGETTER(State))(MediumState_T *aState);
100 STDMETHOD(COMGETTER(Location))(BSTR *aLocation);
101 STDMETHOD(COMSETTER(Location))(IN_BSTR aLocation);
102 STDMETHOD(COMGETTER(Name))(BSTR *aName);
103 STDMETHOD(COMGETTER(DeviceType))(DeviceType_T *aDeviceType);
104 STDMETHOD(COMGETTER(HostDrive))(BOOL *aHostDrive);
105 STDMETHOD(COMGETTER(Size))(ULONG64 *aSize);
106 STDMETHOD(COMGETTER(Format))(BSTR *aFormat);
107 STDMETHOD(COMGETTER(Type))(MediumType_T *aType);
108 STDMETHOD(COMSETTER(Type))(MediumType_T aType);
109 STDMETHOD(COMGETTER(Parent))(IMedium **aParent);
110 STDMETHOD(COMGETTER(Children))(ComSafeArrayOut(IMedium *, aChildren));
111 STDMETHOD(COMGETTER(Base))(IMedium **aBase);
112 STDMETHOD(COMGETTER(ReadOnly))(BOOL *aReadOnly);
113 STDMETHOD(COMGETTER(LogicalSize))(ULONG64 *aLogicalSize);
114 STDMETHOD(COMGETTER(AutoReset))(BOOL *aAutoReset);
115 STDMETHOD(COMSETTER(AutoReset))(BOOL aAutoReset);
116 STDMETHOD(COMGETTER(LastAccessError))(BSTR *aLastAccessError);
117 STDMETHOD(COMGETTER(MachineIds))(ComSafeArrayOut(BSTR, aMachineIds));
118
119 // IMedium methods
120 STDMETHOD(RefreshState)(MediumState_T *aState);
121 STDMETHOD(GetSnapshotIds)(IN_BSTR aMachineId,
122 ComSafeArrayOut(BSTR, aSnapshotIds));
123 STDMETHOD(LockRead)(MediumState_T *aState);
124 STDMETHOD(UnlockRead)(MediumState_T *aState);
125 STDMETHOD(LockWrite)(MediumState_T *aState);
126 STDMETHOD(UnlockWrite)(MediumState_T *aState);
127 STDMETHOD(Close)();
128 STDMETHOD(GetProperty)(IN_BSTR aName, BSTR *aValue);
129 STDMETHOD(SetProperty)(IN_BSTR aName, IN_BSTR aValue);
130 STDMETHOD(GetProperties)(IN_BSTR aNames,
131 ComSafeArrayOut(BSTR, aReturnNames),
132 ComSafeArrayOut(BSTR, aReturnValues));
133 STDMETHOD(SetProperties)(ComSafeArrayIn(IN_BSTR, aNames),
134 ComSafeArrayIn(IN_BSTR, aValues));
135 STDMETHOD(CreateBaseStorage)(ULONG64 aLogicalSize,
136 MediumVariant_T aVariant,
137 IProgress **aProgress);
138 STDMETHOD(DeleteStorage)(IProgress **aProgress);
139 STDMETHOD(CreateDiffStorage)(IMedium *aTarget,
140 MediumVariant_T aVariant,
141 IProgress **aProgress);
142 STDMETHOD(MergeTo)(IMedium *aTarget, IProgress **aProgress);
143 STDMETHOD(CloneTo)(IMedium *aTarget, MediumVariant_T aVariant,
144 IMedium *aParent, IProgress **aProgress);
145 STDMETHOD(Compact)(IProgress **aProgress);
146 STDMETHOD(Resize)(ULONG64 aLogicalSize, IProgress **aProgress);
147 STDMETHOD(Reset)(IProgress **aProgress);
148
149 // public methods for internal purposes only
150 const ComObjPtr<Medium>& getParent() const;
151 const MediaList& getChildren() const;
152
153 // unsafe methods for internal purposes only (ensure there is
154 // a caller and a read lock before calling them!)
155 const Guid& getId() const;
156 MediumState_T getState() const;
157 const Utf8Str& getLocation() const;
158 const Utf8Str& getLocationFull() const;
159 const Utf8Str& getFormat() const;
160 uint64_t getSize() const;
161 MediumType_T getType() const;
162 Utf8Str getName();
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 HRESULT createMediumLockList(bool fMediumWritable, Medium *pToBeParent, MediumLockList &mediumLockList);
188
189 HRESULT createDiffStorage(ComObjPtr<Medium> &aTarget,
190 MediumVariant_T aVariant,
191 MediumLockList *pMediumLockList,
192 ComObjPtr<Progress> *aProgress,
193 bool aWait,
194 bool *pfNeedsSaveSettings);
195
196 HRESULT deleteStorage(ComObjPtr<Progress> *aProgress, bool aWait, bool *pfNeedsSaveSettings);
197 HRESULT markForDeletion();
198 HRESULT unmarkForDeletion();
199 HRESULT markLockedForDeletion();
200 HRESULT unmarkLockedForDeletion();
201
202 HRESULT prepareMergeTo(const ComObjPtr<Medium> &pTarget,
203 const Guid *aMachineId,
204 const Guid *aSnapshotId,
205 bool fLockMedia,
206 bool &fMergeForward,
207 ComObjPtr<Medium> &pParentForTarget,
208 MediaList &aChildrenToReparent,
209 MediumLockList * &aMediumLockList);
210 HRESULT mergeTo(const ComObjPtr<Medium> &pTarget,
211 bool fMergeForward,
212 const ComObjPtr<Medium> &pParentForTarget,
213 const MediaList &aChildrenToReparent,
214 MediumLockList *aMediumLockList,
215 ComObjPtr<Progress> *aProgress,
216 bool aWait,
217 bool *pfNeedsSaveSettings);
218 void cancelMergeTo(const MediaList &aChildrenToReparent,
219 MediumLockList *aMediumLockList);
220
221 HRESULT fixParentUuidOfChildren(const MediaList &childrenToReparent);
222
223 /** Returns a preferred format for a differencing hard disk. */
224 Bstr preferredDiffFormat();
225
226 /** For com::SupportErrorInfoImpl. */
227 static const char *ComponentName() { return "Medium"; }
228
229private:
230
231 HRESULT queryInfo();
232
233 /**
234 * Performs extra checks if the medium can be closed and returns S_OK in
235 * this case. Otherwise, returns a respective error message. Called by
236 * Close() under the medium tree lock and the medium lock.
237 */
238 HRESULT canClose();
239
240 /**
241 * Unregisters this medium with mVirtualBox. Called by Close() under
242 * the medium tree lock.
243 */
244 HRESULT unregisterWithVirtualBox(bool *pfNeedsSaveSettings);
245
246 HRESULT setStateError();
247
248 HRESULT setLocation(const Utf8Str &aLocation, const Utf8Str &aFormat = Utf8Str());
249 HRESULT setFormat(CBSTR aFormat);
250
251 Utf8Str vdError(int aVRC);
252
253 static DECLCALLBACK(void) vdErrorCall(void *pvUser, int rc, RT_SRC_POS_DECL,
254 const char *pszFormat, va_list va);
255
256 static DECLCALLBACK(bool) vdConfigAreKeysValid(void *pvUser,
257 const char *pszzValid);
258 static DECLCALLBACK(int) vdConfigQuerySize(void *pvUser, const char *pszName,
259 size_t *pcbValue);
260 static DECLCALLBACK(int) vdConfigQuery(void *pvUser, const char *pszName,
261 char *pszValue, size_t cchValue);
262
263 class Task;
264 class CreateBaseTask;
265 class CreateDiffTask;
266 class CloneTask;
267 class CompactTask;
268 class ResetTask;
269 class DeleteTask;
270 class MergeTask;
271 friend class Task;
272 friend class CreateBaseTask;
273 friend class CreateDiffTask;
274 friend class CloneTask;
275 friend class CompactTask;
276 friend class ResetTask;
277 friend class DeleteTask;
278 friend class MergeTask;
279
280 HRESULT startThread(Medium::Task *pTask);
281 HRESULT runNow(Medium::Task *pTask, bool *pfNeedsSaveSettings);
282
283 HRESULT taskCreateBaseHandler(Medium::CreateBaseTask &task);
284 HRESULT taskCreateDiffHandler(Medium::CreateDiffTask &task);
285 HRESULT taskMergeHandler(Medium::MergeTask &task);
286 HRESULT taskCloneHandler(Medium::CloneTask &task);
287 HRESULT taskDeleteHandler(Medium::DeleteTask &task);
288 HRESULT taskResetHandler(Medium::ResetTask &task);
289 HRESULT taskCompactHandler(Medium::CompactTask &task);
290
291 struct Data; // opaque data struct, defined in MediumImpl.cpp
292 Data *m;
293};
294
295#endif /* ____H_MEDIUMIMPL */
296
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