VirtualBox

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

Last change on this file since 30787 was 30764, checked in by vboxsync, 15 years ago

back out r63543, r63544 until windows build problems can be solved properly

  • 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 30764 2010-07-09 14:12:12Z 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 VBOX_SCRIPTABLE_IMPL(IMedium)
42{
43public:
44 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(Medium, IMedium)
45
46 DECLARE_NOT_AGGREGATABLE(Medium)
47
48 DECLARE_PROTECT_FINAL_CONSTRUCT()
49
50 BEGIN_COM_MAP(Medium)
51 COM_INTERFACE_ENTRY(ISupportErrorInfo)
52 COM_INTERFACE_ENTRY(IMedium)
53 COM_INTERFACE_ENTRY(IDispatch)
54 END_COM_MAP()
55
56 DECLARE_EMPTY_CTOR_DTOR(Medium)
57
58 HRESULT FinalConstruct();
59 void FinalRelease();
60
61 enum HDDOpenMode { OpenReadWrite, OpenReadOnly };
62 // have to use a special enum for the overloaded init() below;
63 // can't use AccessMode_T from XIDL because that's mapped to an int
64 // and would be ambiguous
65
66 // public initializer/uninitializer for internal purposes only
67 HRESULT init(VirtualBox *aVirtualBox,
68 CBSTR aFormat,
69 CBSTR aLocation,
70 bool *pfNeedsSaveSettings);
71 HRESULT init(VirtualBox *aVirtualBox,
72 CBSTR aLocation,
73 HDDOpenMode enOpenMode,
74 DeviceType_T aDeviceType,
75 BOOL aSetImageId,
76 const Guid &aImageId,
77 BOOL aSetParentId,
78 const Guid &aParentId);
79 // initializer used when loading settings
80 HRESULT init(VirtualBox *aVirtualBox,
81 Medium *aParent,
82 DeviceType_T aDeviceType,
83 const settings::Medium &data);
84 // initializer for host floppy/DVD
85 HRESULT init(VirtualBox *aVirtualBox,
86 DeviceType_T aDeviceType,
87 CBSTR aLocation,
88 CBSTR aDescription = NULL);
89 void uninit();
90
91 void deparent();
92 void setParent(const ComObjPtr<Medium> &pParent);
93
94 // IMedium properties
95 STDMETHOD(COMGETTER(Id))(BSTR *aId);
96 STDMETHOD(COMGETTER(Description))(BSTR *aDescription);
97 STDMETHOD(COMSETTER(Description))(IN_BSTR aDescription);
98 STDMETHOD(COMGETTER(State))(MediumState_T *aState);
99 STDMETHOD(COMGETTER(Location))(BSTR *aLocation);
100 STDMETHOD(COMSETTER(Location))(IN_BSTR aLocation);
101 STDMETHOD(COMGETTER(Name))(BSTR *aName);
102 STDMETHOD(COMGETTER(DeviceType))(DeviceType_T *aDeviceType);
103 STDMETHOD(COMGETTER(HostDrive))(BOOL *aHostDrive);
104 STDMETHOD(COMGETTER(Size))(ULONG64 *aSize);
105 STDMETHOD(COMGETTER(Format))(BSTR *aFormat);
106 STDMETHOD(COMGETTER(MediumFormat))(IMediumFormat **aMediumFormat);
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 const ComObjPtr<MediumFormat> & getMediumFormat() const;
161 uint64_t getSize() const;
162 MediumType_T getType() const;
163 Utf8Str getName();
164
165 HRESULT attachTo(const Guid &aMachineId,
166 const Guid &aSnapshotId = Guid::Empty);
167 HRESULT detachFrom(const Guid &aMachineId,
168 const Guid &aSnapshotId = Guid::Empty);
169
170 const Guid* getFirstMachineBackrefId() const;
171 const Guid* getFirstMachineBackrefSnapshotId() const;
172
173#ifdef DEBUG
174 void dumpBackRefs();
175#endif
176
177 HRESULT updatePath(const char *aOldPath, const char *aNewPath);
178 void updatePaths(const char *aOldPath, const char *aNewPath);
179
180 ComObjPtr<Medium> getBase(uint32_t *aLevel = NULL);
181
182 bool isReadOnly();
183
184 HRESULT saveSettings(settings::Medium &data);
185
186 HRESULT compareLocationTo(const char *aLocation, int &aResult);
187
188 HRESULT createMediumLockList(bool fFailIfInaccessible,
189 bool fMediumLockWrite,
190 Medium *pToBeParent,
191 MediumLockList &mediumLockList);
192
193 HRESULT createDiffStorage(ComObjPtr<Medium> &aTarget,
194 MediumVariant_T aVariant,
195 MediumLockList *pMediumLockList,
196 ComObjPtr<Progress> *aProgress,
197 bool aWait,
198 bool *pfNeedsSaveSettings);
199
200 HRESULT deleteStorage(ComObjPtr<Progress> *aProgress, bool aWait, bool *pfNeedsSaveSettings);
201 HRESULT markForDeletion();
202 HRESULT unmarkForDeletion();
203 HRESULT markLockedForDeletion();
204 HRESULT unmarkLockedForDeletion();
205
206 HRESULT prepareMergeTo(const ComObjPtr<Medium> &pTarget,
207 const Guid *aMachineId,
208 const Guid *aSnapshotId,
209 bool fLockMedia,
210 bool &fMergeForward,
211 ComObjPtr<Medium> &pParentForTarget,
212 MediaList &aChildrenToReparent,
213 MediumLockList * &aMediumLockList);
214 HRESULT mergeTo(const ComObjPtr<Medium> &pTarget,
215 bool fMergeForward,
216 const ComObjPtr<Medium> &pParentForTarget,
217 const MediaList &aChildrenToReparent,
218 MediumLockList *aMediumLockList,
219 ComObjPtr<Progress> *aProgress,
220 bool aWait,
221 bool *pfNeedsSaveSettings);
222 void cancelMergeTo(const MediaList &aChildrenToReparent,
223 MediumLockList *aMediumLockList);
224
225 HRESULT fixParentUuidOfChildren(const MediaList &childrenToReparent);
226
227 /** Returns a preferred format for a differencing hard disk. */
228 Bstr preferredDiffFormat();
229
230private:
231
232 HRESULT queryInfo();
233
234 /**
235 * Performs extra checks if the medium can be closed and returns S_OK in
236 * this case. Otherwise, returns a respective error message. Called by
237 * Close() under the medium tree lock and the medium lock.
238 */
239 HRESULT canClose();
240
241 /**
242 * Unregisters this medium with mVirtualBox. Called by Close() under
243 * the medium tree lock.
244 */
245 HRESULT unregisterWithVirtualBox(bool *pfNeedsSaveSettings);
246
247 HRESULT setStateError();
248
249 HRESULT setLocation(const Utf8Str &aLocation, const Utf8Str &aFormat = Utf8Str());
250 HRESULT setFormat(CBSTR aFormat);
251
252 Utf8Str vdError(int aVRC);
253
254 static DECLCALLBACK(void) vdErrorCall(void *pvUser, int rc, RT_SRC_POS_DECL,
255 const char *pszFormat, va_list va);
256
257 static DECLCALLBACK(bool) vdConfigAreKeysValid(void *pvUser,
258 const char *pszzValid);
259 static DECLCALLBACK(int) vdConfigQuerySize(void *pvUser, const char *pszName,
260 size_t *pcbValue);
261 static DECLCALLBACK(int) vdConfigQuery(void *pvUser, const char *pszName,
262 char *pszValue, size_t cchValue);
263
264 class Task;
265 class CreateBaseTask;
266 class CreateDiffTask;
267 class CloneTask;
268 class CompactTask;
269 class ResetTask;
270 class DeleteTask;
271 class MergeTask;
272 friend class Task;
273 friend class CreateBaseTask;
274 friend class CreateDiffTask;
275 friend class CloneTask;
276 friend class CompactTask;
277 friend class ResetTask;
278 friend class DeleteTask;
279 friend class MergeTask;
280
281 HRESULT startThread(Medium::Task *pTask);
282 HRESULT runNow(Medium::Task *pTask, bool *pfNeedsSaveSettings);
283
284 HRESULT taskCreateBaseHandler(Medium::CreateBaseTask &task);
285 HRESULT taskCreateDiffHandler(Medium::CreateDiffTask &task);
286 HRESULT taskMergeHandler(Medium::MergeTask &task);
287 HRESULT taskCloneHandler(Medium::CloneTask &task);
288 HRESULT taskDeleteHandler(Medium::DeleteTask &task);
289 HRESULT taskResetHandler(Medium::ResetTask &task);
290 HRESULT taskCompactHandler(Medium::CompactTask &task);
291
292 struct Data; // opaque data struct, defined in MediumImpl.cpp
293 Data *m;
294};
295
296#endif /* ____H_MEDIUMIMPL */
297
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