VirtualBox

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

Last change on this file since 30714 was 30714, checked in by vboxsync, 14 years ago

Main: remove SupportErrorInfo template magic

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.0 KB
Line 
1/* $Id: MediumImpl.h 30714 2010-07-07 16:20: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;
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 VirtualBoxSupportTranslation<Medium>,
42 VBOX_SCRIPTABLE_IMPL(IMedium)
43{
44public:
45 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(Medium, IMedium)
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(MediumFormat))(IMediumFormat **aMediumFormat);
108 STDMETHOD(COMGETTER(Type))(MediumType_T *aType);
109 STDMETHOD(COMSETTER(Type))(MediumType_T aType);
110 STDMETHOD(COMGETTER(Parent))(IMedium **aParent);
111 STDMETHOD(COMGETTER(Children))(ComSafeArrayOut(IMedium *, aChildren));
112 STDMETHOD(COMGETTER(Base))(IMedium **aBase);
113 STDMETHOD(COMGETTER(ReadOnly))(BOOL *aReadOnly);
114 STDMETHOD(COMGETTER(LogicalSize))(ULONG64 *aLogicalSize);
115 STDMETHOD(COMGETTER(AutoReset))(BOOL *aAutoReset);
116 STDMETHOD(COMSETTER(AutoReset))(BOOL aAutoReset);
117 STDMETHOD(COMGETTER(LastAccessError))(BSTR *aLastAccessError);
118 STDMETHOD(COMGETTER(MachineIds))(ComSafeArrayOut(BSTR, aMachineIds));
119
120 // IMedium methods
121 STDMETHOD(RefreshState)(MediumState_T *aState);
122 STDMETHOD(GetSnapshotIds)(IN_BSTR aMachineId,
123 ComSafeArrayOut(BSTR, aSnapshotIds));
124 STDMETHOD(LockRead)(MediumState_T *aState);
125 STDMETHOD(UnlockRead)(MediumState_T *aState);
126 STDMETHOD(LockWrite)(MediumState_T *aState);
127 STDMETHOD(UnlockWrite)(MediumState_T *aState);
128 STDMETHOD(Close)();
129 STDMETHOD(GetProperty)(IN_BSTR aName, BSTR *aValue);
130 STDMETHOD(SetProperty)(IN_BSTR aName, IN_BSTR aValue);
131 STDMETHOD(GetProperties)(IN_BSTR aNames,
132 ComSafeArrayOut(BSTR, aReturnNames),
133 ComSafeArrayOut(BSTR, aReturnValues));
134 STDMETHOD(SetProperties)(ComSafeArrayIn(IN_BSTR, aNames),
135 ComSafeArrayIn(IN_BSTR, aValues));
136 STDMETHOD(CreateBaseStorage)(ULONG64 aLogicalSize,
137 MediumVariant_T aVariant,
138 IProgress **aProgress);
139 STDMETHOD(DeleteStorage)(IProgress **aProgress);
140 STDMETHOD(CreateDiffStorage)(IMedium *aTarget,
141 MediumVariant_T aVariant,
142 IProgress **aProgress);
143 STDMETHOD(MergeTo)(IMedium *aTarget, IProgress **aProgress);
144 STDMETHOD(CloneTo)(IMedium *aTarget, MediumVariant_T aVariant,
145 IMedium *aParent, IProgress **aProgress);
146 STDMETHOD(Compact)(IProgress **aProgress);
147 STDMETHOD(Resize)(ULONG64 aLogicalSize, IProgress **aProgress);
148 STDMETHOD(Reset)(IProgress **aProgress);
149
150 // public methods for internal purposes only
151 const ComObjPtr<Medium>& getParent() const;
152 const MediaList& getChildren() const;
153
154 // unsafe methods for internal purposes only (ensure there is
155 // a caller and a read lock before calling them!)
156 const Guid& getId() const;
157 MediumState_T getState() const;
158 const Utf8Str& getLocation() const;
159 const Utf8Str& getLocationFull() const;
160 const Utf8Str& getFormat() const;
161 const ComObjPtr<MediumFormat> & getMediumFormat() const;
162 uint64_t getSize() const;
163 MediumType_T getType() const;
164 Utf8Str getName();
165
166 HRESULT attachTo(const Guid &aMachineId,
167 const Guid &aSnapshotId = Guid::Empty);
168 HRESULT detachFrom(const Guid &aMachineId,
169 const Guid &aSnapshotId = Guid::Empty);
170
171 const Guid* getFirstMachineBackrefId() const;
172 const Guid* getFirstMachineBackrefSnapshotId() const;
173
174#ifdef DEBUG
175 void dumpBackRefs();
176#endif
177
178 HRESULT updatePath(const char *aOldPath, const char *aNewPath);
179 void updatePaths(const char *aOldPath, const char *aNewPath);
180
181 ComObjPtr<Medium> getBase(uint32_t *aLevel = NULL);
182
183 bool isReadOnly();
184
185 HRESULT saveSettings(settings::Medium &data);
186
187 HRESULT compareLocationTo(const char *aLocation, int &aResult);
188
189 HRESULT createMediumLockList(bool fFailIfInaccessible,
190 bool fMediumLockWrite,
191 Medium *pToBeParent,
192 MediumLockList &mediumLockList);
193
194 HRESULT createDiffStorage(ComObjPtr<Medium> &aTarget,
195 MediumVariant_T aVariant,
196 MediumLockList *pMediumLockList,
197 ComObjPtr<Progress> *aProgress,
198 bool aWait,
199 bool *pfNeedsSaveSettings);
200
201 HRESULT deleteStorage(ComObjPtr<Progress> *aProgress, bool aWait, bool *pfNeedsSaveSettings);
202 HRESULT markForDeletion();
203 HRESULT unmarkForDeletion();
204 HRESULT markLockedForDeletion();
205 HRESULT unmarkLockedForDeletion();
206
207 HRESULT prepareMergeTo(const ComObjPtr<Medium> &pTarget,
208 const Guid *aMachineId,
209 const Guid *aSnapshotId,
210 bool fLockMedia,
211 bool &fMergeForward,
212 ComObjPtr<Medium> &pParentForTarget,
213 MediaList &aChildrenToReparent,
214 MediumLockList * &aMediumLockList);
215 HRESULT mergeTo(const ComObjPtr<Medium> &pTarget,
216 bool fMergeForward,
217 const ComObjPtr<Medium> &pParentForTarget,
218 const MediaList &aChildrenToReparent,
219 MediumLockList *aMediumLockList,
220 ComObjPtr<Progress> *aProgress,
221 bool aWait,
222 bool *pfNeedsSaveSettings);
223 void cancelMergeTo(const MediaList &aChildrenToReparent,
224 MediumLockList *aMediumLockList);
225
226 HRESULT fixParentUuidOfChildren(const MediaList &childrenToReparent);
227
228 /** Returns a preferred format for a differencing hard disk. */
229 Bstr preferredDiffFormat();
230
231private:
232
233 HRESULT queryInfo();
234
235 /**
236 * Performs extra checks if the medium can be closed and returns S_OK in
237 * this case. Otherwise, returns a respective error message. Called by
238 * Close() under the medium tree lock and the medium lock.
239 */
240 HRESULT canClose();
241
242 /**
243 * Unregisters this medium with mVirtualBox. Called by Close() under
244 * the medium tree lock.
245 */
246 HRESULT unregisterWithVirtualBox(bool *pfNeedsSaveSettings);
247
248 HRESULT setStateError();
249
250 HRESULT setLocation(const Utf8Str &aLocation, const Utf8Str &aFormat = Utf8Str());
251 HRESULT setFormat(CBSTR aFormat);
252
253 Utf8Str vdError(int aVRC);
254
255 static DECLCALLBACK(void) vdErrorCall(void *pvUser, int rc, RT_SRC_POS_DECL,
256 const char *pszFormat, va_list va);
257
258 static DECLCALLBACK(bool) vdConfigAreKeysValid(void *pvUser,
259 const char *pszzValid);
260 static DECLCALLBACK(int) vdConfigQuerySize(void *pvUser, const char *pszName,
261 size_t *pcbValue);
262 static DECLCALLBACK(int) vdConfigQuery(void *pvUser, const char *pszName,
263 char *pszValue, size_t cchValue);
264
265 class Task;
266 class CreateBaseTask;
267 class CreateDiffTask;
268 class CloneTask;
269 class CompactTask;
270 class ResetTask;
271 class DeleteTask;
272 class MergeTask;
273 friend class Task;
274 friend class CreateBaseTask;
275 friend class CreateDiffTask;
276 friend class CloneTask;
277 friend class CompactTask;
278 friend class ResetTask;
279 friend class DeleteTask;
280 friend class MergeTask;
281
282 HRESULT startThread(Medium::Task *pTask);
283 HRESULT runNow(Medium::Task *pTask, bool *pfNeedsSaveSettings);
284
285 HRESULT taskCreateBaseHandler(Medium::CreateBaseTask &task);
286 HRESULT taskCreateDiffHandler(Medium::CreateDiffTask &task);
287 HRESULT taskMergeHandler(Medium::MergeTask &task);
288 HRESULT taskCloneHandler(Medium::CloneTask &task);
289 HRESULT taskDeleteHandler(Medium::DeleteTask &task);
290 HRESULT taskResetHandler(Medium::ResetTask &task);
291 HRESULT taskCompactHandler(Medium::CompactTask &task);
292
293 struct Data; // opaque data struct, defined in MediumImpl.cpp
294 Data *m;
295};
296
297#endif /* ____H_MEDIUMIMPL */
298
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