VirtualBox

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

Last change on this file since 29945 was 29325, checked in by vboxsync, 15 years ago

Main/Machine: fix regression due to negated bool parameter resulting in incorrec
t locking (dvds/floppies), some cleanup to reduce confusion

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